C# process.start,如何知道进程是否结束? [英] C# process.start, how do I know if the process ended?

查看:47
本文介绍了C# process.start,如何知道进程是否结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我可以用

process.start(program.exe);

process.start(program.exe);

如何判断程序是否仍在运行,或者是否已关闭?

How do I tell if the program is still running, or if it closed?

推荐答案

MSDN 系统.诊断过程

如果您想立即了解,可以查看 HasExited 属性.

If you want to know right now, you can check the HasExited property.

var isRunning = !process.HasExited;

如果过程很快,就等着吧.

If it's a quick process, just wait for it.

process.WaitForExit();

如果您在后台启动,请在将 EnableRaisingEvents 设置为 true 后订阅 Exited 事件.

If you're starting one up in the background, subscribe to the Exited event after setting EnableRaisingEvents to true.

process.EnableRaisingEvents = true;
process.Exited += (sender, e) => {  /* do whatever */ };

这篇关于C# process.start,如何知道进程是否结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆