很久没有提问也没有时间回答问题了,提个关于服务的问题,希望大家帮个忙!(100分)

  • 主题发起人 主题发起人 叮当猫
  • 开始时间 开始时间

叮当猫

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls;

type
TService1 = class(TService)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;

var
Service1: TService1;
i:integer;
StrLstTmp:TstringList;
implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
Service1.Controller(CtrlCode);
end;

function TService1.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;

procedure TService1.Timer1Timer(Sender: TObject);
begin
//showmessage('haha');
i:=i+1;
Strlsttmp.Add(inttostr(i));
end;

procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
begin
i:=0;
timer1.Enabled:=true;
StrLstTmp:=TstringList.Create;
end;

procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
//ShowMessage(inttostr(i));
StrLsttmp.SaveToFile('d:/service.txt');
StrLsttmp.Free;
end;

end.
其中TIMER1的时间间隔设置为5000;
请问这样写服务有问题吗?我只是做个测试,这么写,可是竟然不行,服务停止不了?
我设置服务为可以停止和暂停,启动类型为手动,可是怎么会这样呢?

 
stop timer while srvstop
 
[:(]
唉,什么也没有动,今天重新编译,重新启动,全部正常,靠,受不了,放分了[:(]
 
后退
顶部