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

时间:2011-10-19 03:02:22

标签: mongodb mongodb-.net-driver

每当handleResponse调用委托函数“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;
    }
}           

1 个答案:

答案 0 :(得分:0)

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

相关问题