Waiting for a Process to Finish

  • Thread starter Thread starter bg_ie
  • Start date Start date
B

bg_ie

Hi,

I'm starting a process as follows -

Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = installValue + "\\Lib\\site-packages\
\pythonwin\\Pythonwin.exe";
process.StartInfo.Arguments = "/run " + script;

process.Start();
process.WaitForExit();

when the user presses a button on my GUI. The problem is that my
program is blocked until python is closed. Instead, I'd like to
disable all buttons in my appilcation until python is closed. That way
my program is not blocked but I can still stop the user changing
settings until python is closed.

Should I create a Process which polls process.WaitForExit() or is
there a better/easier way of doing this?

Thanks,

Barry.
 
Should I create a Process which polls process.WaitForExit() or is
there a better/easier way of doing this?

Instead of polling, it is better to connect your code to the event
"Exited" of the Process class.
 
Instead of polling, it is better to connect your code to the event
"Exited" of the Process class.

Cool, thanks for the suggestion. I tried it out but I now have another
problem. I now disable my controls before running the Python process,
but when I attempt to re-enable them via the callback for the Exited
event, I am informed that I cannot access the controls from another
thread other than the one they were created in. So I guess I need to
issue an event to my form thread to tell it to re-enable the controls.
But how do I do that?

Thanks again for your help,

Barry.
 
Cool, thanks for the suggestion. I tried it out but I now have another
problem. I now disable my controls before running the Python process,
but when I attempt to re-enable them via the callback for the Exited
event, I am informed that I cannot access the controls from another
thread other than the one they were created in. So I guess I need to
issue an event to my form thread to tell it to re-enable the controls.
But how do I do that?

See http://pobox.com/~skeet/csharp/threads/winforms.shtml

Jon
 
Back
Top