Вниз
Скачать: CL | DM;

Сервисы (Службы)   Найти похожие ветки 

 
Phoenix77   (2009-11-19 17:47) [0]

Разбираюсь с написание сервисов (служб) и по ходу возник вопрос: как сделать, чтобы после выполнения обработчика OnServiceExecute служба продолжала работать. Например с переодичностью водила ShowMessage?


program Project1;

uses
 SvcMgr,
 Unit1 in "Unit1.pas" {Service1: TService};

{$R *.RES}

begin
 // Windows 2003 Server requires StartServiceCtrlDispatcher to be
 // called before CoRegisterClassObject, which can be called indirectly
 // by Application.Initialize. TServiceApplication.DelayInitialize allows
 // Application.Initialize to be called from TService.Main (after
 // StartServiceCtrlDispatcher has been called).
 //
 // Delayed initialization of the Application object may affect
 // events which then occur prior to initialization, such as
 // TService.OnCreate. It is only recommended if the ServiceApplication
 // registers a class object with OLE and is intended for use with
 // Windows 2003 Server.
 //
 // Application.DelayInitialize := True;
 //
 if not Application.DelayInitialize or Application.Installing then
   Application.Initialize;
 Application.CreateForm(TService1, Service1);
 Application.Run;
end.



unit Unit1;

interface

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

type
 TService1 = class(TService)
   procedure ServiceExecute(Sender: TService);
 private
   { Private declarations }
 public
   function GetServiceController: TServiceController; override;
   { Public declarations }
 end;

var
 Service1: TService1;

implementation

{$R *.DFM}

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

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

procedure TService1.ServiceExecute(Sender: TService);
begin
 Sleep(3000);
 ShowMessage("Hello");
end;

end.


 
clickmaker ©   (2009-11-19 17:54) [1]

> с переодичностью водила ShowMessage?

кому? служба интерактивная?
вообще, обычно так пишут

while not Terminated do begin
 // что-то делаем
 ServiceThread.ProcessRequests(True);
end;

либо создают отдельные потоки для разных задач


 
Phoenix77   (2009-11-19 17:57) [2]

все понятно, спасибо!!!



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.01 c
2-1258701942
Андрей Смирнов
2009-11-20 10:25
2010.01.10
D2009 PChar является PWideChar, как правельно?


15-1257844079
oO
2009-11-10 12:07
2010.01.10
Delphi и Антивирус


15-1257712925
POOP
2009-11-08 23:42
2010.01.10
При отражении длина световой волны меняется?


15-1257856074
oxffff
2009-11-10 15:27
2010.01.10
Уважаемый модератор. Почисти и мой последний пост в теме


15-1256567711
savva
2009-10-26 17:35
2010.01.10
К обладателям клиента форумного..




   Наверх