Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is ServiceBase.ServiceHandle? Any examples?

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.ServiceHandle.
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

like image 858
marcelo-ferraz Avatar asked Oct 26 '25 12:10

marcelo-ferraz


1 Answers

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.

like image 66
Matt Davis Avatar answered Oct 29 '25 03:10

Matt Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!