I am trying to execute a Process.Start() that is a long running process, and show a circular progress bar on the screen while the process is executing.
I have the following lines of code:
Process p =
Process.Start(longRunningProcess);
// show the circular progress bar;
ShowHideCirProgBar(true);
// wait till the process ends execution
p.WaitForExit();
// hide the circular progress bar
ShowHideCirProgBar(false);
I am new to the threading model and not sure how to implement that for the above. Any help will be greatly appreciated.
Thanks,
PJ
Unfortunately, calling:
Will cause your program execution to block until the spawned executable exits. This will prevent WPF from processing its message pump, which in turn will prevent your progress bar from updating properly.
The normal way to handle this is to disable your UI elements, then spawn the process in a background thread, showing your progress. When the process completes, re-enable the UI elements. Using .NET 4, this could be something like:
Alternatively, you can do the same thing via a BackgroundWorker: