asynchronous - C# MDI Forms mixing the code execution -


i developing tcp client server application , receiving packet clients asynchronously , have in server 2 winforms:

  • frmmain main server form mdi parent.
  • frmclient child form instantiated every client when connecting.

i invoking frmclient below code

private static void onclientconnect(iasyncresult asyn)     {         try         {             tcpclient clientsocket = default(tcpclient);              clientsocket = _listener.endaccepttcpclient(asyn);             clientsocket.receivebuffersize = 1024;              showformforclient(clientsocket);                         }         catch (exception se)         {             throw;         }          waitforclientconnect();     }       public static void showformforclient(tcpclient clientsocket)     {         // check if on different thread , redirect if         if (rootform.invokerequired)         {             rootform.begininvoke((methodinvoker)delegate { showformforclient(clientsocket); });             return;         }                     lstform.add(new frmclient(clientsocket,rootform));         lstform.last<frmclient>().mdiparent = rootform;         lstform.last<frmclient>().text= "client : " + clientsocket.client.remoteendpoint;         lstform.last<frmclient>().show();                 } 

and inside class of frmclient when client send handshake message update .text property of client frmclient instance :

private void prochndsh(frame frame)     {         frame _frame = new frame();         frame_message _msg = new frame_message();         _frame = frame;         _msg = _frame.messageref;                     frmmain.sockdic.add(new frmmain.info_client(_frame.conclient,this,_endpoint), _msg.msghost);         this._hostname = _msg.msghost;         this.text = this._hostname + ": " + this._endpoint;         this._is_handshaked = true;         //_parent.listboxclients.items.add(_hostname);         this.show();     } 

this works fine if 1 client connected. if client connected , @ moment sometimes .text property changed in 1st client window not in client made handshake.

what strange first window .text shows new client hostname + old client endpoint(ip:port). suggestions?


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -