这里我有一个代码块,它执行:
public override void Execute(XObjectList itemList, ProcessInfo processInfo) {
ManualResetEvent syncEvent = new ManualResetEvent(false);
execute(itemList, processInfo);
//openScreen();
Thread STAThread = new Thread(() => {
var window = new Window();
window.Content = new MailViewerView();
window.Show();
syncEvent.Set();
});
STAThread.SetApartmentState(ApartmentState.STA);
STAThread.Start();
syncEvent.WaitOne();
}我希望在最后一行之后,打开窗口,进程本身停止,但是调用执行的线程只会一次又一次地迭代。对我做错了什么有什么建议吗?
**如果我在syncEvent.WaitOne()中设置了时间,则更新后台进程的调试屏幕以及UI显示,但UI是不可访问的。对此有什么帮助吗?
**附加信息我想要这样做,因为调用execute方法本身的线程是我无法访问的东西,我想停止这个线程并显示它的一个迭代的UI。因此,这看起来像是糟糕的编码,但这是我唯一能想到的绕过它的方法。
**做以下工作时更新:
public override void Execute(XObjectList itemList, ProcessInfo processInfo) {
ManualResetEvent syncEvent = new ManualResetEvent(false);
execute(itemList, processInfo);
//openScreen();
Thread STAThread = new Thread(() => {
var window = new Window();
window.Content = new MailViewerView();
window.Show();
syncEvent.WaitOne();
syncEvent.Set();
});
STAThread.SetApartmentState(ApartmentState.STA);
STAThread.Start();
}屏幕显示,执行线程正在等待,但屏幕上没有任何内容是可访问的。有什么办法可以克服这个问题吗?
发布于 2015-06-02 14:54:54
因此,最后,初始代码示例没有什么问题,如果我实际上调用了ShowDialog(),它将完全按照预期执行,如下所示:
public override void Execute(XObjectList itemList, ProcessInfo processInfo) {
execute(itemList, processInfo);
ManualResetEvent syncEvent = new ManualResetEvent(false);
//openScreen();
Thread STAThread = new Thread(() => {
var window = new Window();
window.Content = new MailViewerView();
window.ShowDialog();
syncEvent.Set();
});
STAThread.SetApartmentState(ApartmentState.STA);
STAThread.Start();
syncEvent.WaitOne();
}https://stackoverflow.com/questions/30598400
复制相似问题