unit uMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls, DBXpress, WideStrings,
DB, SqlExpr;
type
TSvc =
class(TService)
Timer: TTimer;
SQLCon: TSQLConnection;
procedure ServiceContinue(Sender: TService;
var Continued: Boolean);
procedure ServiceExecute(Sender: TService);
procedure ServicePause(Sender: TService;
var Paused: Boolean);
procedure ServiceStart(Sender: TService;
var Started: Boolean);
procedure ServiceStop(Sender: TService;
var Stopped: Boolean);
procedure TimerTimer(Sender: TObject);
private
{ Private-Deklarationen }
public
function GetServiceController: TServiceController;
override;
{ Public-Deklarationen }
end;
var
Svc: TSvc;
implementation
uses uGlobal, uHandling_File, uHandling_Updates;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
Svc.Controller(CtrlCode);
end;
function TSvc.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TSvc.ServiceContinue(Sender: TService;
var Continued: Boolean);
begin
Continued := True;
end;
procedure TSvc.ServiceExecute(Sender: TService);
begin
//Service läuft die ganze Zeit und Wartet auf Anfragen... False ergibt 100% Auslastung, True nicht
While NOT Terminated
Do Begin
ServiceThread.ProcessRequests(True);
End;
{while}
end;
procedure TSvc.ServicePause(Sender: TService;
var Paused: Boolean);
begin
Paused := True;
end;
procedure TSvc.ServiceStart(Sender: TService;
var Started: Boolean);
begin
Started := True;
Timer.Interval := 1000;
Timer.Enabled := True;
pLog(True, MOD_SYS, '
Service wird gestartet...');
end;
procedure TSvc.ServiceStop(Sender: TService;
var Stopped: Boolean);
begin
Stopped := True;
pLog(True, MOD_SYS, '
Service wird beendet...');
end;
procedure TSvc.TimerTimer(Sender: TObject);
begin
//Timer für die Zeit der verarbeitung abschalten
Timer.Enabled := False;
//Timer Interval setzen...
Timer.Interval := 1000 * 60 * DelayTime;
//Datenbank verbindung öffnen
If NOT SQLCon.Connected
Then Begin
Try
SQLCon.Open;
Except
On E:
Exception Do Begin
pLog(True, MOD_Sys, '
Fehler beim Verbinden mit der Datenbank!');
pLog(True, MOD_Sys, E.
Message);
End;
{on}
End;
{try}
End;
{if}
If SQLCon.Connected
Then Begin
//Update Routinen ausführen...
pUpdateMessAnz;
//Verbindung beenden falls noch offen...
SQLCon.Close;
End;
{if}
//Timer wieder einschalten
Timer.Enabled := True;
end;
end.