Getting a Process to terminate

268 views Asked by At

I have a process object setup like the following:

Process p = new Process();
p.StartInfo.FileName = command;
p.StartInfo.UseShellExecute = true;
p.StartInfo.Arguments = String.Format(
    commandArguments,
    destinationLocation,
    sourceLocation,
    sourceDirName,
    (string.IsNullOrEmpty(revisionNotes.Text)) ? "" : revisionNotes.Text);

(where undefined values are supplied externally to this code and are valid). The process in question launches and properly executes with p.Start(); but i need to catch it on termination. The console window flashes up briefly and goes away which would seem to indicate that the process is done, but none of the relevant events are fired (OutputDataRecieved, Exited, etc) and it's like the process never ends. (I'm trying to execute a lua script with some parameters if that's relevant). Can someone help me get this process to stop correctly?

2

There are 2 answers

3
MartW On BEST ANSWER

Have you set the EnableRaisingEvents property of the process to True? You won't catch the Exited event without it.

0
Darin Dimitrov On