Mongodb C Sharp GUI/Socket在GUI更新时崩溃

Mongodb C Sharp GUI/Socket在GUI更新时崩溃,mongodb,mongodb-.net-driver,Mongodb,Mongodb .net Driver,每当HandlerResponse调用委托函数func时,我的GUI都会崩溃,没有例外。委托函数将文本附加到GUI上的RichTextBox 如果我在connect中调用this.func,它就可以正常工作 private void handleResponse(IAsyncResult result) { try { this.func.Invoke("test"); } catch (Exception e) { thr

每当HandlerResponse调用委托函数func时,我的GUI都会崩溃,没有例外。委托函数将文本附加到GUI上的RichTextBox

如果我在connect中调用this.func,它就可以正常工作

private void handleResponse(IAsyncResult result)
{
    try
    {
        this.func.Invoke("test");
    }
    catch (Exception e)
    {
        throw e;
    }
}

public void connect(string ip, int port, delegateFunction func) {     
    try
    {
        connection.Connect(ip, port);
        socket = connection.Client;
        this.func = func;            
        socket.BeginReceive(incomingBuffer, 0, incomingBuffer.Length, SocketFlags.None, handleResponse, null);
    }
    catch (Exception e)
    {
        throw e;
    }
}           

可能是线程问题。您的GUI可能必须在特定的GUI线程上更新。如何切换到该线程取决于您使用的GUI框架