views:

100

answers:

1

Hey, In the main thread I need to do the following:

  1. Create a second thread where I'll show a modal form that will act as an "activity indicator"
  2. Start a task (this task MUST be executed from the main thread)
  3. Close the modal form created in the second thread.

The question is that I don't know how to show a modal form and not stop the main thread.

Any suggestion?

+1  A: 

I would use a ThreadPool thead... something like...

ThreadPool.QueueUserWorkItem(o => dlg.Show());

This will launch the dialog on a separate thread. Your main thread will continue processing.

RichAmberale
That won't be modal. You'll want to use ThreadPool.QueueUserWorkItem(() => dlg.ShowDialog(this););
SnOrfus
Rich, I appreciate your reply.Actually I knew how to show a form from a second thread. what I didn't know is how to show the form as modal at the second thread and then, after I completed my work from the main thread, tell the second thread to close the form.I ended up solving my problem putting a control variable inside my Form. Something like "canDie". I do ShowModal in the second thread (the thread doesnt die) I do what I want to do in the main thread and after that I switch canDie to true inside de form, it closes and finishes my second thread.Anyway I votted you up.Thanks.
Ciwee
Another observation: Modal forms when in another thread are not acually modal. For them to behave correctly we must set the TopMost property to true
Ciwee