Threading - load data on a different thread and bind and display a messagebox after done.
Posted on 2007-10-15
I am using C# 1.1.
I have a form with a Load button. When the button is clicked, it takes about 20 seconds to get the data and load. I want to do this over a different thread.
So I use a Thread, ThreadStart and a MethodInvoker. A new Thread is started using a ThreadStart and that thread calls back the main thread for binding the data obtained and for showing a message box saying "Data is loaded". So when the user clicks on the button and remains on the same window, the message box is shown as a Dialog window. But when the user clicks on the button and goes to a different Taskbar item, the message box is shown as a non-dialog item, with it's own entry on the taskbar and it is no more modal. The same is the case when some exception is thrown in the child thread.
How do I make the same behavior both when the current window is selected or otherwise?