1

我在 WPF 中的 STA 线程遇到了一些问题。

我执行以下操作:

Dispatcher.BeginInvoke(new Action(CreateAndShow), null);

CreateAndShow 看起来像这样:

_mainWindow = new PresentWindow();
// not really important what happens in the next lines, the error is before this
AddPerspectives(); 
MainWindow = _mainWindow;
MainWindow.Show();

现在,我在 PresentWindow 构造函数开始的行中得到一个异常,指出调用线程需要是一个 STA 线程。

我在创建 PresentWindow 之前设置了一个断点。当前线程的 AppartmentState 是 STA。如果我从不同的点调用 CreateAndShow(没有调用,但直接在完全相同的 STA 线程中),它工作得非常好。

我敢肯定这一切都有一个非常简单的解释,但我找不到。有人可以帮忙吗?

谢谢!

4

0 回答 0