Die Delphi-Dienstanwendung wird nach 15 Sekunden gestoppt, der Timer wird nicht ausgeführt
Ich möchte eine Dienstanwendung in Delphi erstellen, die täglich um 14.00 Uhr einige Dateien ausführt und kopiert. Also habe ich Timer verwendet. Die Steuerung geht jedoch nicht zum Timer-Ereignis über, und der Dienst wird innerhalb von 15 Sekunden beendet. Ich habe einen Code für Timer Event geschrieben. Wie kann ich den Timer für den Service verwenden? Bitte helfen Sie. Danke im Voraus.
Mein Code ist hier:
unit untMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.SvcMgr, Vcl.Dialogs, Vcl.ExtCtrls, DateUtils, Vcl.Forms,
untCommon;
type
TsrvBackupService = class(TService)
tmrCopy: TTimer;
procedure tmrCopyTimer(Sender: TObject);
private
strlstFiles : TStringList;
{ Private declarations }
public
{ Public declarations }
end;
var
srvBackupService: TsrvBackupService;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
srvBackupService.Controller(CtrlCode);
end;
procedure TsrvBackupService.tmrCopyTimer(Sender: TObject);
var
strCurTime : string;
strBKPpath : string;
strBKPTime : string;
NowDay : word;
NowMonth : word;
NowYear : word;
NowHour : word;
NowMin : word;
NowSec : word;
NowMilli : Word;
begin
DecodeTime(now,NowHour,NowMin,NowSec,NowMilli);
strCurTime := IntToStr(NowHour)+':'+IntToStr(NowMin);
strBKPTime := '14:00'
strBKPpath := ExtractFilePath(Application.ExeName);
if strCurTime = strBKPTime then begin
Try
CopyFile(PChar('c:\datafile.doc'),PChar(strBKPpath + 'datafile.doc'),true);
except
on l_e: exception do begin
MessageDlg(l_E.Message,mtError,[mbOk],0);
end;
end;
end;
end;
end.