Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The service could not be started, but does start?

I've written a small windows service that I want to run daily on my Windows Server 2008. The service is written in C#.

  • The code works great in a normal Windows Form.
  • The service works like it should when I start and stop it from the Services Management window (services.msc).

But when running it on a commandline with:

net start Service1

I get the the following:

The Service1 service is starting........  The Service1 service could not be started.

The service did not report an error.

More help is available by typing NET HELP:SG 3534.

The weird thing is though, the service is still running, in the Services screen I still see it as starting untill it's fully started. When I try to stop the service afterwards I get:

The service could not be controlled in its present state.

More help is available by typing NET HELPMSG 2189

And then the service is stopped. Is there any way in solving this? I've already managed to debug the service without any problems, the code works. But during debugging the same thing still happens on the command console, while I'm still able to debug further.

It's like there is some kind of timeout on the onStart() method.. I have no idea.. I'm fairly new to Windows Services (this is my first one). I do write all my code in the onStart() method, maybe that's not the best idea, but I don't know where else to type it.

If someone could help I'd greatly appreciate it.

like image 332
Floris Devriendt Avatar asked May 10 '11 08:05

Floris Devriendt


People also ask

How do I fix the service Cannot be started?

Click Start > Run > services. Locate and double click on the Windows Management Instrumentation service. The Windows Management Instrumentation service Properties window opens. Locate and change the Startup Type to Automatic. The Startup Type is changed.

How do I force a service to start?

Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to start a service and press Enter: net start "SERVICE-NAME" In the command, replace "SERVICE-NAME" for the name or display name of the service.

Why would a Windows service fail to start?

Why will my Windows Service not start? Make sure that the service's dependencies are running. Make sure that the service is not set to DISABLED. Sometimes when the service is set to log on as the local system account (default) for some reason, perhaps local permissions, it is unable to launch.

How do I fix my disabled Security Center?

Restart the Windows Security Center Service Press Win + R to open the Run command dialog box. Type services. msc and press Enter to open the Services window. Locate the Windows Security Center, right-click on it, and then click Restart.


1 Answers

The OnStart event is used to launch a background thread that will take care of the processing. If the OnStart method finishes without error, the service manager assumes the service started successfully. As such, the OnStart should return as soon as possible.

The OnStop method is then used to stop the background processing. A successful OnStop tells the service manager that the service was closed without error.

like image 146
Johann Blais Avatar answered Oct 30 '22 02:10

Johann Blais