相关疑难解决方法(0)

跨线程操作无效

调试时我一直收到以下错误.

Cross-thread operation not valid: Control 'richTextBoxReceivedMsg' accessed from a thread other than the thread it was created on.
Run Code Online (Sandbox Code Playgroud)

这是它指向的代码:

public void OnDataReceived(IAsyncResult asyn)
{
    try
{
    SocketPacket socketData = (SocketPacket)asyn.AsyncState;

    int iRx  = 0;

        // Complete the BeginReceive() asynchronous call by EndReceive() method
        // which will return the number of characters written to the stream by the client
        iRx = socketData.m_currentSocket.EndReceive (asyn);

        char[] chars = new char[iRx +  1];
        System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
        int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, …
Run Code Online (Sandbox Code Playgroud)

c# sockets multithreading winforms

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

multithreading ×1

sockets ×1

winforms ×1