In C# or .NET, is there a way to prevent other threads from invoking methods on a particular thread?

Posted by YWE on Stack Overflow See other posts from Stack Overflow or by YWE
Published on 2010-04-30T18:46:04Z Indexed on 2010/04/30 18:57 UTC
Read the original article Hit count: 154

Filed under:
|
|

I have a Windows Forms application with a BackgroundWorker. In a method on the main form, a MessageBox is shown and the user must click the OK button to continue. Meanwhile, while the messagebox is being displayed, the BackgroundWorker finishes executing and calls the RunWorkerCompleted event. In the method I have assigned to that event, which runs on the UI thread, the Close method is called on the form. Even though the method that shows the message box is still running, the UI thread is not blocking other threads from invoking methods on it. So the Close method gets called on the form. What I want is for the UI thread to block other threads' invokes until the method with the message box has finished. Is there an easy way to do that?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about threading