maybe you have slow internet and something is wrong with the code
Windows Service not really running after shutdown...
I've written a service in Visual Studio that manages a folder, so far, things work just fine until you shutdown the computer then start back up, the service shows that it is running but it actuality, its not as there are no event logs created from the service. Now the weird thing is when you physically restart the service or just simply reboot the machine, everything works as it should, logs are sent to event viewer and the services executes as it should. I've set the dependencies of the service with the event viewer to ensure that service is running prior to this service starting up. Its also running on a local system account. In the OnStart() event, its calling a backgroundworker class to read some information from a text file to set some variables the service needs then starts a timer. Like I said, everything runs fine except when you shutdown the machine.
Why would a service act this way on a hard start meaning showing that its actually running when its not.
it is because maybe you have a slow internet
Now this is interesting...
I developed a simple service with the same components, one event log, one timer, one background worker, In the OnStart() event, i fire the background worker off and write one event and set the timer to run. I get the same effect, service runs as it should and makes one entry at startup (either service restart or machine restart) and once per minute (ran by the timer), but, when you shutdown the machine then start back up, the service shows that its running in services, but there are no event logs written. WHY???
Hi @Davido , Glad to see your problem solved, you could accept the helpful answer to change its status to Answered. It will also help others to solve the similar issue.
Thanks for your cooperation.
Sign in to comment
Sort by: Most helpful
way out in left field...
One, service does not rely on internet what so ever, then two, if something was wrong with the code it would throw an error when it runs after a manual restart or a soft reset (known as a windows restart) as the same code is executed each time.
@Davido, If your system is configured to use Fast Startup then the system does not stop services when you use shutdown. Instead, the system enters a hibernate state. Consequently, the next time the system is started its state is restored from hibernation which includes those services that were running previously. So from your service perspective, it was not stopped at shut down and is still running when the system state is restored at the next startup.
That's very interesting, never would have figured that one out...
So from a service prospective without having a hidden form or other, how do you detect that and fire things off again? Seen a bunch of post about creating scripts, hidden programs etc, not wanting to reinvent the wheel but i am sure others have figured out a way. I do know according to MS, you cannot detect power changes from within as service, you must have a hidden form to pass those messages...
so my next question is, does the service go into a paused state?
How to force into shutdown instead of hibernate? Hibernate takes power and I prefer to pay PG&E less. For conservation and save $$. Another part of this is when I tell my machine to shutdown that is what I want it to do. Not go into a mode other than shutdown, turn computer off and boot again when I, and only I, choose to bring it active.
@Davido , Have you tried handling ServiceBase.OnPowerEvent(PowerBroadcastStatus) Method?
Thanks, I finally figured that piece out now yesterday and the service is doing as it should. Like I said, thanks for pointing the "Fast Startup" out, would have never thought of that. One takes for face value that a machine is shutting down instead of hibernating.
Sign in to comment