Showing A Dialog in the main thread from a Seperate thread

I am doing some checking of data in a seperate thread other than the main GUI thread.  Occasionally, I want to notify the user of something and I want the Dialog to behave like a normal Modal Dialog Box.  How can I accomplish this?   (if you call ShowDialog in a seperate thread, the dialog is non-modal).  
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Create a synchronized queue: Queue myQueue = Queue.Synchronized(new Queue);
Then fill the queue with data (enqueue) in your working thread and dequeue the items in the main thread and show the messages. You can use a System.Windows.Forms.Timer to check periodically the queue. Attention: There are 3 classes named "Timer"! Only one is working in the main thread.
I think the best way is using invoke()
taken from Threading Support in the .NET Framework ->By Markus Egger, Software Architect, EPS Software Corporation
private void DisplayCustomers(DataSet dsCustomers)
   this.dataGrid1.DataSource =dsCustomers.Tables["customers"];

private void DisplayCustomers_TS(DataSet dsCustomers)
   DisplayCustomersDelegate oDel = new
   DisplayCustomersDelegate(  this.DisplayCustomers);
   DataSet[] args = {dsCustomers};
delegate void DisplayCustomersDelegate(DataSet dsCustomers);

The first line instantiates a delegate that points to our original DisplayCustomers()
method. (Note that the last line in this snippet defines the delegate.) When then proceed
to create an array of DataSet objects with a single item (our customer DataSet). Finally,
we call the Invoke() method with our delegate and the DataSet in the array of
arguments. If you are not familiar with Delegates, this may look a bit confusing at first,
but it is really quite straightforward. We simply point the Invoke() method to another
method and say ?See this method there? Go ahead and run it for me??.
And that does the trick! The only thing that?s left to do is make the LoadCustomers() call
DisplayCustomers_TS() instead of DisplayCustomers(). Now our little application is
perfectly thread-safe!

I think you can use this mechanism for your code ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
How are you telling the delegate in which thread it should be executed??

What could help are ContextBound objects but I've never used them. Else Microsoft is also suggesting methods like the one I described above.

BTW: I'm also Software Architect in a world wide Software Company, but here we should not try to impress with names and titles but with facts.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Ok, Control.Invoke works, you're right. Control.Invoke does the synchronizing stuff. Delgates alone don't do any synchronizing. I didn't realize that in "this.Invoke(oDel,args);" "this" is of type Control.
jjacksnAuthor Commented:
Does Invoke only work with delagates?  
Yes, as you see in the help or msdn Control.Invoke(Delegate) or Control.Invoke(Delegate, object[]).
If you use Invoke, the current thread is suspended until the main thread completed the delegate. You can use BeginInvoke / EndInvoke to call the method asynchronous then the current thread continues working.
taken from Threading Support in the .NET Framework ->By Markus Egger, Software Architect, EPS Software Corporation
I was only talking about a whitepaper, which is the reference for the solution copied...
Yes, you're right it's good to list the reference. Since I can not edit my old comment it will forever stay...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.