delphi service application stop after 15 second, timer not executing

前端 未结 3 1430
梦如初夏
梦如初夏 2021-01-16 08:35

I want to make service application in Delphi that run and copy some files everyday at 02:00 PM. So i have used timer. but control not going to timer event and Service termin

3条回答
  •  日久生厌
    2021-01-16 09:32

    When you say "service terminates after 15 seconds" it makes me think you are debugging the code.

    If you don't have any option and can't use what others suggested, with the code above the timer event is triggered properly when you install and start the service via services.msc. However, if you are debugging the service, the timer event will not be triggered and the aplication will terminate (as you said). I would create a procedure to be called inside timer event, and call it once in ServiceExecute event, so you could debug like this:

    procedure TSomeService.ServiceExecute(Sender: TService);
    begin
      ExecuteSomeProcess(); // Put breakpoint here to debug
      while not self.Terminated do
        ServiceThread.ProcessRequests(true);
    end;
    
    procedure TSomeService.TimerTimer(Sender: TObject);
    begin
      timer.Enabled := false;
      ExecuteSomeProcess(); // This can't throw any exception!
      timer.Enabled := true;
    end;
    

提交回复
热议问题