views:

69

answers:

6

Hi,

I have a C# WinForms program thats starts another Process. The program then waits until the Process has finished.

Currently I use Process.WaitForExit(), but this means that while my program waits for the Process to end, it doesn't repaint and "looks" like it's not responding.

Is there any way for the Window of the Process that my program starts, be modal to my main form (i.e. you can't switch back to my program & the window repaints)?

Basically I want to do something like Form.ShowDialog(), except using the Process's Window as the Form to be shown as a dialog.

A: 

Create Form, Show it modal. then use BackgroundWorker to start process and handle RunWorkerCompleted event to close the form.

Orsol
A: 

Why don't you start your process in a separate thread? That way, only your thread will wait. This way, your form will still respond.

sbenderli
+1  A: 

You can't prevent the user from switching back because you've spawned a separate process. As far as the operating system is concerned it's as if you'd started the second one via it's desktop icon (for example).

I think the best you can hope for is to disable the relevant menus/options when the second process is active. You'll need to keep polling to see if it's still alive, otherwise your main application will become unusable.

Another approach might be to minimize the main application which will keep it out of the way.

ChrisF
A: 

You could create another form which you make modal. On that form load you would call Visible = false; then you would start a thread which starts your process and waits for it to finish via the thread.

Then do a BeginInvoke(new MethodInvoker(delegate { Close(); } )); from within the thread after the wait for complete finishes.

Brian R. Bondy
A: 

You should definately create a new thread and from that thread, launch the application you are trying to launch. This will make your application responsive, even while the other application is running

icemanind
A: 
  1. Use the process.Exited event to know when the application exits.
  2. Hook the Activated (think it's the correct name) event in you form. Use it to bring the other application to focus.
jgauffin