How can I get ShowDialog to return from a background thread?
I have a WPF application built on top of a C ++ / CLR framework that listens for messages sent by the framework. One particular message is so important that I need to close all current windows. However, if the modal Dialog (created by ShowDialog from my main window) is active and is waiting for user input, the window will not close because it is waiting for ShowDialog return. How to force modal Dialog to close and unlock code execution?
I tried installing DialogResult or calling Close , however it does not seem to work.
Edit: Dialog is created by my main window, which expects a return value, for example: (inside the 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 structure sends a message (entering a different thread than the UI thread), I call MainWindow.Close() . The modal dialog box closes at this point, however, the verification code for the Dialog return value (after ShowDialog ) is still on the stack. Somehow this makes the main window not disappear.
Hypherion
source share