Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows service stops automatically

I made a Window service and let it work automatically and under localsystem account, when the service starts it fires this message for me and then stops

The [service name] service on local computer started and then stopped. Some Services stop automatically if they are not in use by another services or programs.

What's the problem and what's the solution?

like image 701
netseng Avatar asked Feb 11 '09 21:02

netseng


People also ask

Why services are stopped automatically?

Some Services stop automatically if they are not in use by another services or programs. What's the problem and what's the solution? this error would occur with a Java service when the Java policy doesn't allow proper permissions, such as "policy.

How do you fix some services stop automatically if they are not in use by other services or programs?

You can fix this by going to the list of services, right click on desired service, click properties on context menu and then change "Log On As" to "Local system account" if it is not the same as shown in below image. Show activity on this post.

Does Windows service run continuously?

Once the win service is started then this process will run continuously in background.


2 Answers

Either you are not starting any threads on the OnStart method to do work, or there is an exception raised within your OnStart method.

If an exception is thrown, it will appear in the Windows Event log. The Windows Event log is a good place to start in any case.

Generally an OnStart method looks like this:

Thread _thread;  protected override void OnStart(string[] args) {     // Comment in to debug     // Debugger.Break()      // Do initial setup and initialization     Setup();      // Kick off a thread to do work     _thread = new Thread(new MyClass().MyMethod)     _thread.Start();      // Exit this method to indicate the service has started } 
like image 74
Robert Wagner Avatar answered Sep 19 '22 23:09

Robert Wagner


This particular error message means what it says - that your service has started but then quite soon it exited for some reason. The good news is that your service is actually doing something, so you have the executable configured and running as a service properly.

Once started, for some reason it is quitting. You need to find out why this is. Add some debugging to tell you its up and running and known exit cases. If that doesn't reveal the problem then add some debugging to let you know it's still running and work backwards from when that stops.

like image 36
Mat Avatar answered Sep 21 '22 23:09

Mat