Hey,
this method get's in an ifinitive loop,
If I send a message to this server, it get's the message but it keeps adding the message to the textbox.
What's wrong with this? And what is the correct way to build this method?
thx
public void OnDataReceived(IAsyncResult asyn) { if (this.InvokeRequired) { Invoke(new AsyncCallback(OnDataReceived), asyn); } else { try { SocketPacket socetPacket = (SocketPacket)asyn.AsyncState; int iR = 0; iR = socetPacket.thisSocket.EndReceive(asyn); char[] characters = new char[iR + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(socetPacket.dataBuffer, 0, iR, characters, 0); StringBuilder Data = new StringBuilder(); for (int teller = 0; teller < characters.Length; teller++) { Data.Append(characters[teller]); } txtData.Text = txtData.Text + Data; WaitForData(socWorker); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { MessageBox.Show(se.Message); } } cmdListen.Enabled = true; }