Windows Service not really running after shutdown...

Davido 0 Reputation points
2023-05-03T15:17:46.46+00:00

Morning

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.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,606 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,570 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-05-03T15:26:11.78+00:00

    maybe you have slow internet and something is wrong with the code

    0 comments No comments

  2. Davido 0 Reputation points
    2023-05-03T15:54:54.5333333+00:00

    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.

    0 comments No comments

  3. RLWA32 40,286 Reputation points
    2023-05-03T16:21:20.9433333+00:00

    @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.