system.invalidoperationexception跨线程操作无效

时间:2018-03-13 16:26:30

标签: c#

private void MessageCallBack(IAsyncResult aResult)
{
    try
    {
        byte[] receivedData = new byte[1500];
        receivedData = (byte[])aResult.AsyncState;
        //Converting byte[] to string
        ASCIIEncoding aEncoding = new ASCIIEncoding();
        string receivedMessage = aEncoding.GetString(receivedData);

        //Adding this message into Listbox
        listMessage.Items.Add("Friend : " + receivedMessage);
        //TextBox.CheckForIllegalCrossThreadCalls = false;

        buffer = new byte[1500];
        sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

0 个答案:

没有答案