The service cannot be started, but is it starting?

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

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

But when it starts on the command line with:

net start Service1 

I get 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. 

Strange, however, the service is still working, on the Services screen, I still see it as a beginning until it starts up completely. When I try to stop the service, 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 to solve this? I already managed to debug the service without any problems, the code works. But during debugging, it still happens on the console, but I can still debug further.

This is similar to some timeout onStart () method. I have no idea. I am new to Windows Services (this is my first). I write all my code in the onStart () method, maybe this is not a good idea, but I do not know where else to enter it.

If anyone can help, I would really appreciate it.

+6
source share
1 answer

The OnStart event is used to trigger a background thread that will handle processing. If the OnStart method completes without errors, the service manager assumes that the service started successfully. Thus, OnStart should return as soon as possible.

Then, the OnStop method is used to stop background processing. A successful OnStop tells the service manager that the service was shut down without error.

+4
source

Source: https://habr.com/ru/post/887690/


All Articles