无法在回调方法wpf中打开Window

时间:2016-11-24 19:12:03

标签: c# wpf multithreading sockets user-interface

当在socket.BeginReceive的回调方法中打开Window时,显示错误:调用线程必须是STA,因为许多UI组件都需要这个。

int id = pr.ReadInt32();
BinaryWriter bw = new BinaryWriter();
if (!InCall)
{
   string name = null;
   Incoming_Call IncmCall = new Incoming_Call();
   InCall = (bool)IncmCall.ShowDialog();        

1 个答案:

答案 0 :(得分:0)

使用 Dispatcher.BeginInvoke 强制UI线程打开新窗口