Reputation: 1022
I have a window which runs from a thread, let's call it MainThread, and a background thread which performs other non-graphical tasks.
Sometimes the background thread will call the MessageBox.Show(...)
method (which is modal and stops the background thread). Before this call, I would like to suspend the MainThread and resume it after so that my MainWindow's controls are disabled while the messageBox
is shown.
So my questions are:
Upvotes: 2
Views: 414
Reputation: 564363
Instead of suspending the main thread, you could use Control.Invoke
(Windows Forms) or Dispatcher.Invoke
(WPF) to actually show the message box on the main thread, but call it from your background thread.
In addition to providing the behavior you wish, this would also have that advantage of allowing you to parent your message box to the proper Window, which would give the proper modal message box behavior.
Upvotes: 3