Главная страница
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.014 c
1-1233071230
harisma
2009-01-27 18:47
2010.01.10
Скролл в TreeView


2-1258473755
6699
2009-11-17 19:02
2010.01.10
Файлы


6-1210789618
EgorovAlex
2008-05-14 22:26
2010.01.10
При сканировании определённого сегмента сети я нахожу адреса,


2-1258706506
2012
2009-11-20 11:41
2010.01.10
проблема с созданием сервиса (Stopped = False)


2-1258470387
Pascal96
2009-11-17 18:06
2010.01.10
Задача на сортировку.