2011-10-19 34 views
0

每当handleResponse调用委托函数“func”我的GUI崩溃,没有例外。委托函数将文本附加到GUI上的RichTextBox。C图形用户界面/套接字崩溃的GUI更新

如果我在“连接”中调用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; 
    } 
}   

回答

0

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

相关问题