Service Application not working correctly

I have created a service application and installed on my windows machine.
Now i can see service in services on machine. Also it works fine for some time.
After some time it stops working and when i try to Stop or Restart service it won’t work. it says “Service can not accept control message at this time”
i am not getting if it is problem with my code or something else.
Can anyone help me with this?

If you can create a simple version of your project that demonstrates this issue & link to it here I can have a look to see what may be going wrong.

Start by checking the Windows event log. When things go wrong in a service, Windows often manages to log the exceptions in the log.

Actually my code works fine, it fails only some time or may be after running few hours. So it is not possible to show you the issue.

And when it fails to work i can’t Start-Stop-Restart the service. i am getting following message-
“Service can not accept control message at this time”

Is this message related to some setting which i have forgotten ?

Is this statement necessary for Windows Service - call Daemonize

I have a service on Windows that gets itself stuck sometimes. Usually better error detection and handling is the answer. Or if the service puts itself into an infinite loop it won’t respond to Windows.

If you can run the program from the CMD prompt, at least temporarily, you might see an error message.

Also watch the process and the memory consumption over time, things failing after working for hours sometimes are due to memory leaks.