开发者

What is ServiceBase.ServiceHandle? Any examples?

开发者 https://www.devze.com 2023-03-04 11:19 出处:网络
I am working in a service that watches the file system for a modification/addition/removal of anything inside a folder. As I started to implement it, I\'d met this property, inside the ServiceBase cla

I am working in a service that watches the file system for a modification/addition/removal of anything inside a folder. As I started to implement it, I'd met this property, inside the ServiceBase class, ServiceBase.Serv开发者_开发百科iceHandle.

What is this used for? What can I achieve with it? I tried googling about it, but found little more than the MSDN site told me already.

Do someone know some example or a tutorial how to use it?

thanks


The ServiceBase.ServiceHandle is the system handle used to update the service's status in the Services control panel. It is the same handle returned by the Win32 RegisterServiceCtrlHandler and RegisterServiceCtrlHandlerEx functions.

All services have the responsibility of updating their status. In unmanaged services, such as those created in C++, this was the responsibility of the developer. You'd pass the handle and the updated status (e.g., START_PENDING, RUNNING, STOPPED) as input to the Win32 SetServiceStatus function when the status changed.

Even in managed services, such as those created with C#, the developer is still responsible for updating the status; it's just that the ServiceBase class performs all of the status updates for you.

In short, I would say that this handle is completely unnecessary for managed services that inherit from ServiceBase.

0

精彩评论

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