You call WaitForExit
before you subscribe Exited
event, so thread will wait there till process exits and never subscribes the event before the process exits. When WaitForExit
returns process is already exited, then only you subscribe Exited
event which is never going to fire again.
So subscribe Exited
event before you call WaitForExit
.
process.Exited += (@Sender, args) =>
{
tcs.SetResult(process);
System.Windows.MessageBox.Show("Done");
process.Dispose();
};
process.WaitForExit();