开发者

Do function on process close?

开发者 https://www.devze.com 2023-01-01 19:24 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消