【发布时间】:2012-06-24 18:39:04
【问题描述】:
TcpClient DataReadAsyncCallback 是否在主 UI 线程中执行? 我正在从该处理程序创建 Windows 窗体,经过几次调用和窗口显示应用程序只是终止,没有任何来自 .NET 的异常。
...
ns.BeginRead(client.RxPacket, 0, client.RxPacket.Length, new AsyncCallback(TcpClientDataReadAsyncCallback), client);
...
private void TcpClientDataReadAsyncCallback(IAsyncResult ar)
{
Client client = (Camera)ar.AsyncState;
// read data
// create window form with that data recieved
MyForm form = new MyForm(/*read data passed*/);
form.Show();
}
或者我应该使用委托来跟踪来自另一个线程的 UI 访问?
【问题讨论】:
标签: c# multithreading asynchronous tcpclient