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 访问?