I am new to windows services. I created an installer for my C # Windows service, and the installation on the server (Windows Server 2003) seems to have worked. When it starts, it writes Service started successfully
to the log. When he stopped, he writes Service stopped successfully
. However, sometimes the service stops working without writing anything to the log, so I start it manually. When I look at the log later, it says Service started successfully
, as expected. It is strange to see that two times in a row in a magazine is that there is clearly no entry in which the service somehow stopped working.
What could be the reason for this? I have a service configured as automatic, and it has been installed for all users. I got the impression that this means that the service starts automatically whenever the machine boots. How can I find out why it stopped? Are cases that the failure is automatically recorded in the event log, or do I have to handle the exceptions so that they register their own cause of the failure?
Edit: Additional information:
- I set it to log in as a local system account
- In the "Recovery options" section, I configured it to reboot on the first failure. I have nothing for the second or subsequent failures.
Update:. The responder recommended a global exception handler. Although I will not apply this as a permanent fix, it will at least help me figure out where the problem is. I really tested this with the installed service and it works. I found out that unhandled exceptions actually destroy the service without writing anything to the log at all. I thought that he would at least report some application error, but it is not.
static void Main() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
source share