[英]How to capture an app start-up in a service?
Try to create a windows service with VS 2012. By default, there are 3 methods for the service: 尝试使用VS 2012创建Windows服务。默认情况下,该服务有3种方法:
Constructor(say MyService)
OnStart
OnStop
but when I put some code in Constructor, looks like it only running one time. 但是当我将一些代码放入Constructor中时,它看起来似乎只运行了一次。
What I want is: when an app started from windows, for example, notepad.exe, I can capture it. 我想要的是:当某个应用程序从Windows启动时,例如notepad.exe,我可以捕获它。 Should I put a dead loop in the constructor to monitor process list?
是否应该在构造函数中放置死循环以监视进程列表? I thought Service should be always on like a dead loop.
我认为Service应该一直处于死循环状态。 So when an app start it, how to capture it in MyService?
因此,当应用启动时,如何在MyService中捕获它?
Should I put a dead loop in the constructor to monitor process list?
是否应该在构造函数中放置死循环以监视进程列表?
No, that goes in OnStart()
. 不,这在
OnStart()
。 Basic pseudo-code is: 基本的伪代码是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.