Here I have a block of code that executes:
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();
}
I expect to after the last line, the window to open and the process itself to stop, but the thread that calls the execute just iterates again and again. Any pointers as to what I am doing wrong?
**UPDATE If I set a time in the syncEvent.WaitOne(), the debug screen of the background process as well as the UI displays, except the UI is not accessible. Any help with this?
**Additional Info I want to do this as the thread that calls the execute method itself is something that I can't access, I want to stop that thread and display the UI for one iteration of it. So it may seem like bad coding, but it is the only way I can think of to get around it.
**UPDATE When doing the following:
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();
}
The screen does show and the execute thread is waiting, but nothing on the screen is accessible. Any ideas as to overcome this part?
So in the end there was nothing wrong with the initial code sample, it would do exactly as intended if I actually called ShowDialog(), as seen here:
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();
}