Ohh Thanks..
I will try to test as you suggested..
I have some doubts to ask you.. about your very first answer to my post..
Here is that:
You mean to say for every service there is the timeperiod defind under WaitToKillServiceTimeout value in the registry which stops the service after this much period of time .. Right ..?
Ohh.. Thanks..
But I am a bit crazy about .. As you guessed .. that there might be something which is resisting my service from stoping in timely manner..If this is the case , what if there is the service with WaitToKillServiceTimeout as 600000 , after every 10 minutes the servic's OnStutdown() should get called..i.e. The Logs should get printed .. as i did in my test application ..If I have not mistaken you point..Please correct me if I am wrong.
If there is something which is stoping my service in the timely manner.. what could be it.. Can you please help me.. can you give me any suggestions ..
As per as the code is concern..
I created the simple windows service .. overrided OnStop(), OnShutDown(),OncustomeCommand() fun.. Rest are the common.. constructors.. etc.
About OS : My service running on Windows serverv 2008 / Vista
Please let me know your feedback over this..
Thanks
The WaitToKillServiceTimeout is only (as far as I'm aware) evaluated as the system is shutting down - I don't believe it is constantly revisited throughout the lifetime of the Windows Session, just the one time as you're closing down.
When you ask the system to restart/shutdown, it issues the shutdown command to each of the active services and then waits either for the period specified in the registry key (oddly, it doesn't appear to shutdown earlier if all the processes are shut down successfully prior to the completion of that time period), so for instance, if you have Exchange installed, and the WaitToKillServiceTimeout has been increased to 10 minutes, but on shutdown all the services still complete their shutdown processes in let's say 2 minutes and 30 seconds...the system still sits there and dutifully waits the full 10 minutes - whoever's idea
that was, was a genius (note the sarcasm in my voice). Once the period has elapsed, the system indiscriminately kills all remaining active services thus removing them from memory in whatever state they were in, at the time they were killed.
Now, if something is preventing your service shutting down in a timely manner, I'm not sure and not really able to tell. The only way to really figure this out is to have the very first statements in your OnShutdown() method to spit out some form of output to say that the shutdown method has at least been called. Whether or not it shuts down in a timely manner is due to whatever other code is inside your method. If it never reaches the end of the method, then it is deemed to have not shut down in a timely manner and will be killed off when the WaitToKillServicesTimeout period has elapsed... but at the very least,
some of the calls inside the method should have been executed.