Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to implement Stop method in a windows service?

I'm looking at some legacy code in the form of a Windows service.

I've noticed that in their OnStop() method, they simply write to the event log, however there is no object clean-up or control of terminating any threads. There are 2 background threads which are started on startup of the service so I'm left wondering, does this service actually stop? And, if it does, are the threads closed down correctly?

Is the stop method physically terminating the process or is it only a logical stop, which if left not implemented doesn't actually do anything?

like image 995
jaffa Avatar asked Feb 01 '13 16:02

jaffa


1 Answers

The OnStop() method is called when the service is stopped you can clear the objects and stop the threads etc here. If your thread do not need any thing special to do when service is stopped then you can leave the OnStop method

OnStop is expected to be overridden in the derived class. For the service to be useful, OnStart and OnStop should both be implemented in your service class, msdn

like image 147
Adil Avatar answered Nov 05 '22 00:11

Adil