Page 1 of 1
For a Windows Service...
Posted: Thu Jun 02, 2011 4:24 pm
by RichAlgeni
How often should we update Service_UpdateStatus()? Once per second? Too much? Not enough?
Code: Select all
rightNow = ElapsedMilliseconds()
If (rightNow - lastElapsed) > 999; update the service status once per second
lastElapsed = rightNow
Service_UpdateStatus()
EndIf
Re: For a Windows Service...
Posted: Sat Jun 04, 2011 2:40 am
by RichAlgeni
Should have been more clear, we don't update, we check the status via Service_UpdateStatus.
This is done to enable the service to be stopped from services.msc.
I can't find a definitive answer on MSDN on how often this should be done, other than not going longer than 120 seconds between checks. One thing I did find is that if your service is multi-threaded, you must stop all threads before reporting to the SCM that the service is stopped, otherwise the SCM could get confused.
Can you imagine? Microsoft code gets confused?!?
The horror!

Re: For a Windows Service...
Posted: Mon Aug 22, 2011 6:09 pm
by SFSxOI
You can't find a definitive answer because there is none. You check the status of the service when you need to check it as there is no defined time limit requirement for this or that, and other then that if your concerned about, or need, status changes then you can get notifications on status with a check before entering a procedure or routine that relies on the status of the service. You don't need to check the status continually "to enable the service to be stopped from services.msc" as you just stop (or start) it when you need to do so, and the same with its status as you just check it when you need it.
Its up to the specific needs or what the person doing the code wants to do, and thats why there is no definitive answer and you make your own 'definitive' answer by determining what your requirements are for your code.