reatart记事本(未运行)的服务 [英] Service to reatart notepad if it is not running
问题描述
大家好,
我正在尝试创建一个简单的Windows服务,该服务将检测notepad.exe是否正在运行.如果它停止运行,我希望它再次打开记事本.最初,我有一个控制台应用程序,该应用程序仅循环并使用Process.GetProcesses("notepad.exe").但是总是 循环我注意到我使用了太多的CPU.不确定如何在服务中实现相同的逻辑,但实际上只是想在不使用过多CPU的情况下执行此操作.非常感谢任何帮助
I am trying to create a simple windows service that will detect if notepad.exe is running. If it stops running I want it to open notepad again. Originally, I had a console app that just loops and uses Process.GetProcesses("notepad.exe"). But always looping I noticed I was using too much CPU. Not sure how to implement this same logic in a service, but essentially just want to do this without using too much CPU. Any help greatly appreciated
推荐答案
对于您的控制台应用程序,您可以创建一个计时器并检查计时器滴答事件中的状态.
For your console app, you could create a timer and check the status in the timer tick event.
迈克
这篇关于reatart记事本(未运行)的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!