L
laobeli
Unregistered / Unconfirmed
GUEST, unregistred user!
程序功能,每五秒中更新服务的系统时间,为什么线程类中的输出文本文件能执行 FList.Add('123');
FList.SaveToFile('c:/aaaa.txt');而更新时间不能执行呢?
winexec( pchar('net time //192.168.1.18 /set /y'),SW_hide);
unit ServiceMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;
type
TSkyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
TSkyrityService = class(TService)
procedure ServiceContinue(Sender: TService; var Continued: Boolean);
procedure ServiceExecute(Sender: TService);
procedure ServicePause(Sender: TService; var Paused: Boolean);
procedure ServiceShutdown(Sender: TService);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
{ Private declarations }
FSkyThread: TSkyThread;
FList:TStringList;
public
function GetServiceController: TServiceController; override;
procedure GT;
{ Public declarations }
end;
var
SkyrityService: TSkyrityService;
implementation
uses MainForm;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
SkyrityService.Controller(CtrlCode);
end;
function TSkyrityService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TSkyrityService.ServiceContinue(Sender: TService;
var Continued: Boolean);
begin
while not Terminated do
begin
Sleep(10);
ServiceThread.ProcessRequests(False);
end;
end;
procedure TSkyrityService.ServiceExecute(Sender: TService);
begin
while not Terminated do
begin
Sleep(10);
ServiceThread.ProcessRequests(False);
end;
end;
procedure TSkyrityService.ServicePause(Sender: TService;
var Paused: Boolean);
begin
Paused := True;
end;
procedure TSkyrityService.ServiceShutdown(Sender: TService);
begin
//gbCanClose := true;
FrmMain.Free;
Status := csStopped;
ReportStatus();
end;
procedure TSkyrityService.ServiceStart(Sender: TService;
var Started: Boolean);
begin
Started := True;
flist:= tstringlist.Create;
FSkyThread:= TSkyThread.Create(false);
Svcmgr.Application.CreateForm(TFrmMain, FrmMain);
//gbCanClose := False;
//FrmMain.Hide;
end;
procedure TSkyrityService.ServiceStop(Sender: TService;
var Stopped: Boolean);
begin
Stopped := True;
//gbCanClose := True;
FrmMain.Free;
end;
procedure TSkyrityService.GT;
begin
FList.Add('123');
FList.SaveToFile('c:/aaaa.txt');
winexec( pchar('net time //192.168.1.18 /set /y'),SW_hide);
end;
{ Cservicetest }
procedure TSkyThread.Execute;
begin
inherited;
while not Terminated do
begin
SkyrityService.GT;
sleep(5000);
end;
end;
end.
FList.SaveToFile('c:/aaaa.txt');而更新时间不能执行呢?
winexec( pchar('net time //192.168.1.18 /set /y'),SW_hide);
unit ServiceMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;
type
TSkyThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
TSkyrityService = class(TService)
procedure ServiceContinue(Sender: TService; var Continued: Boolean);
procedure ServiceExecute(Sender: TService);
procedure ServicePause(Sender: TService; var Paused: Boolean);
procedure ServiceShutdown(Sender: TService);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
{ Private declarations }
FSkyThread: TSkyThread;
FList:TStringList;
public
function GetServiceController: TServiceController; override;
procedure GT;
{ Public declarations }
end;
var
SkyrityService: TSkyrityService;
implementation
uses MainForm;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
SkyrityService.Controller(CtrlCode);
end;
function TSkyrityService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TSkyrityService.ServiceContinue(Sender: TService;
var Continued: Boolean);
begin
while not Terminated do
begin
Sleep(10);
ServiceThread.ProcessRequests(False);
end;
end;
procedure TSkyrityService.ServiceExecute(Sender: TService);
begin
while not Terminated do
begin
Sleep(10);
ServiceThread.ProcessRequests(False);
end;
end;
procedure TSkyrityService.ServicePause(Sender: TService;
var Paused: Boolean);
begin
Paused := True;
end;
procedure TSkyrityService.ServiceShutdown(Sender: TService);
begin
//gbCanClose := true;
FrmMain.Free;
Status := csStopped;
ReportStatus();
end;
procedure TSkyrityService.ServiceStart(Sender: TService;
var Started: Boolean);
begin
Started := True;
flist:= tstringlist.Create;
FSkyThread:= TSkyThread.Create(false);
Svcmgr.Application.CreateForm(TFrmMain, FrmMain);
//gbCanClose := False;
//FrmMain.Hide;
end;
procedure TSkyrityService.ServiceStop(Sender: TService;
var Stopped: Boolean);
begin
Stopped := True;
//gbCanClose := True;
FrmMain.Free;
end;
procedure TSkyrityService.GT;
begin
FList.Add('123');
FList.SaveToFile('c:/aaaa.txt');
winexec( pchar('net time //192.168.1.18 /set /y'),SW_hide);
end;
{ Cservicetest }
procedure TSkyThread.Execute;
begin
inherited;
while not Terminated do
begin
SkyrityService.GT;
sleep(5000);
end;
end;
end.