Do function on process close?
Say I have created a process using Process.Star开发者_如何学JAVAt();.
How would I tell if it had been closed/terminated, without freezing the application?
Try the following
Process p = Process.Start(...);
p.Exited += OnProcessExited;
private void OnProcessExited(object sender, EventArgs e) {
// Put code here
}
There is one catch to this code though. It's possible for the Process
to exit before the event handler is attached. So you may not receive this event for a Process
which exits quickly.
精彩评论