-1

I have written a windows service in c# that's designed not to stop or restart.

In the constructor, there is a log that writes something like "Starting Application".

So i left it running for more than a week and I can see that the constructor that writes the log is being executed. This leads me to believe the windows service is restarting for unknown reason. There are no errors being thrown!!

Any idea?

Cheers.

ove
  • 3,092
  • 6
  • 34
  • 51
  • 4
    This question is too generic to provide any clue for possible solution. Could you check out the windows event log and, if you have the logger to log starting the application, try gathering as much information as possible before it stops/crashes. – Arthur P Jul 15 '11 at 04:19
  • 1
    "I have written a windows service in c# that's designed not to stop or restart." - How is that a good idea? – Mitch Wheat Jul 15 '11 at 04:20
  • Well. if you work with control system before, then you most probably know the answer. – ove Jul 15 '11 at 05:41

1 Answers1

1

Usually you can see the reason for a service restart by looking in the event viewer. Open it from Administrative Tools under your start menu. Look underneath Windows Logs/Application. Look for anything with your program name or anything that has a Red exclamation mark.

Generally, when writing a windows service, you want ALL of your code to run within a TRY/CATCH block. You can log any error in the catch block if you want (but be careful that your logging code can't throw an exception!). You have to "swallow" the exception in order to let the service keep running.

Devin Garner
  • 1,361
  • 9
  • 20
  • There are a lot of information icon. The descriptions as below. Service started successfully. For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp. But the source name is called Service1 not the name of my service. – ove Jul 15 '11 at 05:58
  • If it was killed by an exception, it should have a red exclamation point with an error. The information icons can probably be ignored, since you're looking for an error. – Devin Garner Jul 15 '11 at 17:15
  • Yes, I dont think my service is killed by any exception. It restarted occasionally and this is strange. No error. – ove Jul 19 '11 at 02:46