multithreading - C# TCP Client sends a message, but Server is not receiving the message -


this error :

**

exception thrown: 'system.invalidoperationexception' in system.windows.forms.dll additional information: cross-thread operation not valid: control 'displaytext' accessed thread other thread created on.

**

i created multi threaded client , server application using on c#. researched error not find relevant answer. know comes when 2 or more threads started on program...but server side has 1 thread...i don't know why comes..........

here server side:

        private void handler()         {             try {                   byte[] b = new byte[100];                 int k = s.read(b, 0, b.length);                  //int k = s.receive(b);                    string szreceived = encoding.ascii.getstring(b,0,k);                 //if data converted available in sequential blocks (such data read stream) or if amount of data large needs divided smaller blocks,                   while (serverrunning)                 {                     string concatstring = "";                     (int = 0; < k; i++)                     {                          char n = convert.tochar(b[i]);                         string chars = convert.tostring(n);                         concatstring = concatstring + chars;                      }                      if (b[0] == '$')                     {                         displaytext.appendtext("\nprivate message");                         //messagebox.show("\nprivate message" + environment.newline);                     }                     else                     {                         displaytext.appendtext("\n" + concatstring);                         //messagebox.show(concatstring + environment.newline);                     }                      //encoding process of transforming set of unicode characters sequence of bytes , using new instance                     asciiencoding asen = new asciiencoding();                      //s.send(asen.getbytes("the string recieved server." + environment.newline));                      displaytext.appendtext("\n" + concatstring);                     /* clean */                     //*                    // k = s.receive(b);                     s.close();                     client.close();                     //messagebox.show("recieved..." + environment.newline);                   }             }             catch(exception ex)             {                 messagebox.show("error ...." + ex);             }         } 

i new socket programming, researched each , every code segment , experimented code in several times.. still can't figure out missed in program...

so please me solve this...i appreciated much... thanks..

invoke((methodinvoker) delegate { displaytext.appendtext("\n" + concatstring); }); 

should fix it; dispatches "append ui" code ui thread , waits complete.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -