locked
Windows application problem starting the service RRS feed

  • Question

  • I'm developing a windows service application and my problem is start the service after the installation.

    Erro: "Error 1053 the service did not respond to the start or control request in a timely fashion"

    this code below is just one test

    if my function OnStart is code below, my service doesn't start

    for(int i = 0; i <= 2000; i++)
    {
        System.Threading.Thread.Sleep(20000);
    }
    but, if i comment the code, the service starts normally

    Tuesday, January 26, 2016 10:32 PM

Answers

  • Hi leomfd_tec,

    As Matthew LEAN . and Sivasankar said, the loop that in OnStart method you have written consuming lot of time to execute.  Based on your code, you may want to start your service once every 20 seconds. If yes, you can use a Timer in your service.

    Some code snippet as following:

    private static Timer timer;
    private const int TimerInterval = 20000;
    
    protected override void OnStart(string[] args)
    {
        var callback = new TimerCallback(checkDatabase);
        this.timer = new Timer(callback, null, 0, TimerInterval);
    }
    
     

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 27, 2016 8:53 AM

All replies

  • Do not execute lengthy work in OnStart method which is not point to do working.

    http://stackoverflow.com/questions/649935/windows-services-onstart-loop-do-i-need-to-delegate


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.

    Wednesday, January 27, 2016 1:05 AM
  • Hi,

    OnStart method should complete as soon as possible. The loop that you have written consuming lot of time to execute. Thus service is not responding. 

    In general, you should only perform setup/initialization on OnStart(). 

    Thanks,

    -Siva

    Wednesday, January 27, 2016 2:52 AM
  • Hi leomfd_tec,

    As Matthew LEAN . and Sivasankar said, the loop that in OnStart method you have written consuming lot of time to execute.  Based on your code, you may want to start your service once every 20 seconds. If yes, you can use a Timer in your service.

    Some code snippet as following:

    private static Timer timer;
    private const int TimerInterval = 20000;
    
    protected override void OnStart(string[] args)
    {
        var callback = new TimerCallback(checkDatabase);
        this.timer = new Timer(callback, null, 0, TimerInterval);
    }
    
     

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 27, 2016 8:53 AM