Форум: "Начинающим";
Текущий архив: 2010.01.10;
Скачать: [xml.tar.bz2];
ВнизСервисы (Службы) Найти похожие ветки
← →
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;
Скачать: [xml.tar.bz2];
Память: 0.44 MB
Время: 0.004 c