windows service in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Proogeren
    New Member
    • May 2007
    • 36

    windows service in C#

    Hello

    I have made a windows service in C#

    When I stop the service under Computer Management | Services I get an error that the service could not be stopped. This occurs not all the time.

    While debugging no exceptions seems to appear, so Im having a hard time figuring out whats wrong.

    Is there a way to detect where an error occurs on a high level?

    help appreciated
  • RoninZA
    New Member
    • Jul 2007
    • 78

    #2
    This might happen if a process in your service takes longer than a certain amount of time to execute.

    What I mean is that Windows allows a certain amount of time for a service to stop, I don't know how long that would be, but let's say, for example, that it's 60 seconds. If you have, say, a Sytem.Threading .Thread.Sleep(1 00000) in your service code, or if the service's System.Timers.T imer's interval is set to longer than 60 seconds, then Windows will assume that the service has failed to stop, regardless of whether it actually has or not. The easiest way to check this is to see if the service does actually stop, even after the error message.

    I suggest adding an OnStop() event to your service, to kill any timers running or and threads that may be sleeping, this should solve the problem.

    Comment

    • Proogeren
      New Member
      • May 2007
      • 36

      #3
      hm service sleeps for 5 seconds..
      But I had timer.setInterv al=0 in my updatetimer_ela psed method. I did this to stop the service when an error occured...
      Now I replaces this with calling the OnStop method when an error occurs..
      Maybe this is was the problem...

      [Additional info] Well my timer is only set to 5 sec and terminated before that. But all errors that can occur in my program will be caught if I have a try catch in my service constructor right?
      Last edited by SammyB; Jul 26 '07, 12:18 PM. Reason: Added info sent with report button

      Comment

      • RoninZA
        New Member
        • Jul 2007
        • 78

        #4
        Should be...

        Problem sorted out?

        Comment

        Working...