How can I force ShowDialog to return from a background thread?
I have a WPF application built on top of a C++/CLR framework which is listening to messages sent by the framework. One particular message is so important that I need to close all the current windows. However, if a modal dialog (created by ShowDialog from my main window) is active and awaiting user input, the window will not close because it is waiting for ShowDialog to return. How can I force the modal dialog to close and unwind code execution?
I tried setting the DialogResult or calling Close however that doesn't seem to work.
Edit: The dialog is created by my main window which expects a return value, like so: (inside a click event handler in MainWindow):
Window modalDialog = new Window();
bool ret = (bool)modalDialog.ShowDialog();
if (ret == true)
{
// do stuff
}
else
{
// do some other stuff
}
When the framework sends a message (coming in on a different thread than the UI thread), I call MainWindow.Close(). The modal dialog gets closed at this point, however the code checking the return value of the dialog (after ShowDialog) is still on the stack. Somehow this forces the main window to not disappear..