none
problem in windows sevice created in c#.net RRS feed

  • Question

  • * I have developed a sevice in c#.net.
    *I installed it using a setup file created through visual studio 08.
    *My service is also visible in local services in control panel.
    *But when i start my service there is an error .The error no is 1053 stating:The service did not respond to start or control request in a timely fashion.
    *Aftr this error the status of the service is 'starting' n i can neither start,stop,pause etc...
    * i added    "thread.sleep(40000)" in the onstart n onpause event.
    * i even dont know to debug the service.
    * Could ne one plz help me to solve this problem...its very important and urgent...
    *plz reply in detail and clearly as iam a junior .net developer..and need a clear idea to understand and implement..
    * do u require my code??
    *Plz do reply..

     


    Mumtaz Surani
    • Moved by edhickey Monday, July 27, 2009 4:15 PM More appropriate forum (From:Microsoft Codename 'Oslo')
    Monday, July 27, 2009 5:53 AM

Answers

  • There are lot's of reason why a Windows Service wont start. Probably there is an exception in the constructor or in OnStart.
    First of all, you should add some tracing. Especially in the constructor and in OnStart. Encapsulate the code with try/catch, and log any exceptions you get.
    You should also add an event handler to: AppDomain.CurrentDomain.UnhandledException in which you should log information about the exception.

    As for debugging, once you have started the service, you can from Visual Studio (when you have the service solution opened) select Debug->Attach to Process, and select the service process. This can of course be a bit difficult if the problem occurs before are able to attach to the process, but this can be overcome by adding a Thread.Sleep() call for instance as the first statement in the constructor.

    Hope this is of help.


    Tor-Odd Connelly
    • Marked as answer by Zhi-Xin Ye Friday, July 31, 2009 12:51 PM
    Monday, July 27, 2009 4:57 PM

All replies

  • There are lot's of reason why a Windows Service wont start. Probably there is an exception in the constructor or in OnStart.
    First of all, you should add some tracing. Especially in the constructor and in OnStart. Encapsulate the code with try/catch, and log any exceptions you get.
    You should also add an event handler to: AppDomain.CurrentDomain.UnhandledException in which you should log information about the exception.

    As for debugging, once you have started the service, you can from Visual Studio (when you have the service solution opened) select Debug->Attach to Process, and select the service process. This can of course be a bit difficult if the problem occurs before are able to attach to the process, but this can be overcome by adding a Thread.Sleep() call for instance as the first statement in the constructor.

    Hope this is of help.


    Tor-Odd Connelly
    • Marked as answer by Zhi-Xin Ye Friday, July 31, 2009 12:51 PM
    Monday, July 27, 2009 4:57 PM
  • Check to make sure the account which the service runs under has the appropriate privileges to do what you want to do....Is there something in the onstart which is may need a resource which it cannot access?
    William Wegerson (www.OmegaCoder.Com)
    Monday, July 27, 2009 5:04 PM
    Moderator
  • First, make sure your sleep time is not causing the error message you are seeing. Second, you can insert a Debug.Assert(False) into the constructor of the service. Build, then run the service, when the window comes up, click 'Retry' and select the version of VS with your code loaded into it. You'll be able to step through it easier than attaching.
    http://blogs.windowsclient.net/joes
    • Edited by Joe Sm Thursday, July 30, 2009 8:58 PM Typo
    Thursday, July 30, 2009 8:58 PM