For a Windows Service...

Windows specific forum
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

For a Windows Service...

Post 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
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: For a Windows Service...

Post 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! :twisted:
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: For a Windows Service...

Post 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.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Post Reply