Reputation: 69
I am Running a WPF application (process A). From this on a button click I need to start another process (process B), which is a WinForms application.
Now my question is if I close process B's window by clicking the (X)-button, which closes process B abruptly then how to notify this event info to process A?
Upvotes: 0
Views: 230
Reputation: 128060
The Process class has an Exited
event for exactly this purpose. You also have to set EnableRaisingEvents
to true
to use it:
private void ButtonClick(object sender, RoutedEventArgs e)
{
var process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.EnableRaisingEvents = true;
process.Exited += ProcessExited;
process.Start();
startButton.IsEnabled = false;
}
private void ProcessExited(object sender, EventArgs e)
{
Dispatcher.BeginInvoke(new Action(() => startButton.IsEnabled = true));
}
Upvotes: 1