Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2010.01.10;
Скачать: 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 вся ветка

Текущий архив: 2010.01.10;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.015 c
2-1258308164
ℓoℓ
2009-11-15 21:02
2010.01.10
Клавиатура в замену джостику


4-1226307753
DimDim
2008-11-10 12:02
2010.01.10
Лажа с округлениями???


1-1217266456
self.name
2008-07-28 21:34
2010.01.10
как лучше сравнить строки


2-1258478697
ℓoℓ
2009-11-17 20:24
2010.01.10
Получение сообщения о нажатии клавищи


2-1258544549
Oleg1963
2009-11-18 14:42
2010.01.10
Ищу родителей. Использование GetParent.