过程监控 [英] Process Monitoring
问题描述
我对 System.Diagnostics.Process 类非常熟悉.但是,我想知道如何监控特定进程(即检查它是否每 XX 分钟/秒运行一次).我需要能够检查进程是否正在运行,如果是,则继续初始化程序的其余部分.
I'm quite familiar with the System.Diagnostics.Process class. But, I'm wondering about how I can monitor a specific process (i.e. Check to see if it's running every XX mins/secs). I need to be able to checking whether a process is running and if it is, continue with initialising the rest of the program.
谢谢,
-扎克
Thanks,
-Zack
推荐答案
如果你没有自己启动进程,你会通过查看返回的列表找到与进程关联的 Process
对象通过 Process.GetProcessesByName(...)
或 Process.GetProcesses(...)
If you didn't start the process yourself, you get find the Process
object associated with a process by looking through the list returned by Process.GetProcessesByName(...)
or Process.GetProcesses(...)
一旦你有了进程,你就可以听读它的属性(包括HasExited
) 和(正如 Jon 在他的回复中提到的)如果你设置了 EnableRaisingEvents
你可以监听它的事件(包括Exited
).
Once you have the process, you can listen read its properties (including HasExited
) and (as Jon mentions in his response) if you set EnableRaisingEvents
you can listen to its events (including Exited
).
这篇关于过程监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!