akshay rasalakar

akshay rasalakar

  • NA
  • 128
  • 9.4k

C# windows chat application

Jun 13 2015 11:00 PM
private void MessageCallBack(IAsyncResult aResult)
{
int size = sck.EndReceiveFrom(aResult, ref epRemote);
if (size > 0)
{
byte[] recevivedData = new byte[1464];
recevivedData = (byte[])aResult.AsyncState;
ASCIIEncoding eEncoding = new ASCIIEncoding();
string recevieMessage = eEncoding.GetString(recevivedData);
listBox1.Items.Add("Friend:" + recevieMessage); //In this Line Im getting error Cross-thread operaation not valid: Control 'listBox1' accessed from a                                                                                     thread other than the thread it was created on
                                                                                   i can send msg to my friend but while receiving the message im getting the error as i mentioned above                                                                                     so pls help me..
}
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
}

Answers (2)