我想在Delphi中使服務應用程序每天運行並複製一些文件在下午2:00。所以我使用了計時器。但控制不會進入計時器事件並且服務在15秒內終止。我在Timer Event上寫了一段代碼。我如何使用計時器與服務?請幫忙。提前致謝。德爾福服務應用程序停止15秒後,定時器不執行
我的代碼是在這裏:
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.
請告訴我們你寫 –
代碼你所描述不是定製的書面服務,但一個計劃的任務 –