Question

I have simplified my code for the sake of this question, but basically what happens is this:

private void RunScript(string path)
{
    Process.Start(path);
    lblStatus.Text = "Step 6 Complete";
}

However, I don't want the label's text to be updated until the script finishes running. Is that possible? Or rather, practical / feasible?

Était-ce utile?

La solution

Just replace your code by this if you want to wait for a maximum given amount of time:

 Process.Start(path).WaitForExit(milli seconds);

or this if you want to wait possibly forever (usually until it finishes)

 Process.Start(path).WaitForExit();

Autres conseils

You can use Process.Start(path).WaitForExit(); that will ... wait for the process to exit before continuing.

Becareful if this is on your main UI thread though as the UI will freeze and become unresponsive whilst it is working. Kick the process off on a BackgroundWorker or similar and update / kick off stage 7 when you get a successful completion (or have to handle an error).

Process.Start returns true when process has started added a do while loop and that should be it

  bool started = Process.Start(path)

http://msdn.microsoft.com/en-us/library/vstudio/e8zac0ca

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top