我在Delphi中创建了一个Windows服务。我的代码在ServiceExecute中运行。
procedure TMyService.ServiceExecute(Sender: TService);
while not Terminated do
begin
CallSomeProcedure;
Sleep(1000);
ServiceThread.ProcessRequests(false);
end;
end;
很遗憾,我无法运行这段代码。即使在调试时,它似乎也没有调用该过程。Myservice.exe中的代码如下。
begin
if not Application.DelayInitialize or Application.Installing then
Application.Initialize;
Application.CreateForm(TMyService, MyService);
Application.Run;
end.
如果我添加
,我就可以运行serviceExecute。MyService.ServiceExecute(nil);
把 MyService.exe 安装为服务后,似乎不能作为应用程序运行,因为 Application.Run 没有任何反应。
不确定我做错了什么,但任何帮助将不胜感激。
谢谢。