title: thread in service application under delphi xe does not work
body: <p>'MyThread' does not run. I do not know whether the problem happens on 'DataTransferServiceStart' procedure. I guess the 'DataTransferServiceStart' procedure does not execute. IDE is Delphi XE. Please help me, thank you very much.</p>
  
  <p>Thread's Unit:</p>
  
  <pre><code>unit Unit_MyThread;
  
  interface
  
  uses
    Classes, SysUtils;
  
  type
    TMyThread = class(TThread)
    private
      { Private declarations }
    protected
      procedure Execute; override;
    end;
  
  implementation
  
  
  procedure TMyThread.Execute;
  var
    log: TextFile;
    logPath: String;
    i: Integer;
  begin
    logPath := 'd:\test.log';
    AssignFile(log, logPath);
    Append(log);
    i := 0;
    while not self.Terminated do
    begin
      Sleep(1);
      Writeln(log, IntToStr(i));
      if i=10 then
        Terminate;
      i := i + 1;
    end;
    CloseFile(log);
  end;
  
  end.
  </code></pre>
  
  <p>Main Service Unit:</p>
  
  <pre><code>unit Unit_main;
  
  interface
  
  uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
    ExtCtrls, DB, ADODB, Unit_MyThread;
  
  type
    TDataTransferService = class(TService)
    DBSrc: TADOConnection;
  
    procedure DataTransferServiceStart(Sender: TService; var Started: Boolean);
    procedure DataTransferServiceContinue(Sender: TService; var Continued: Boolean);
    procedure DataTransferServicePause(Sender: TService; var Paused: Boolean);
    procedure DataTransferServiceStop(Sender: TService; var Stopped: Boolean);
  
    public
      function GetServiceController: TServiceController; override;
    end;
  var
    DataTransferService: TDataTransferService;
    MyThread: TMyThread;
  implementation
  
  {$R *.DFM}
  
  procedure ServiceController(CtrlCode: DWord); stdcall;
  begin
    DataTransferService.Controller(CtrlCode);
  end;
  
  function TDataTransferService.GetServiceController: TServiceController;
  begin
    Result := ServiceController;
  end;
  
  procedure TDataTransferService.DataTransferServiceStart(Sender: TService;
    var Started: Boolean);
  begin
    MyThread := TMyThread.Create(False);
    Started := True;
  end;
  
  procedure TDataTransferService.DataTransferServiceContinue(Sender: TService;
    var Continued: Boolean);
  begin
    MyThread.Start;
    Continued := True;
  end;
  
  procedure TDataTransferService.DataTransferServicePause(Sender: TService;
    var Paused: Boolean);
  begin
    MyThread.Suspended := true;
    Paused := True;
  end;
  
  procedure TDataTransferService.DataTransferServiceStop(Sender: TService;
    var Stopped: Boolean);
  begin
    MyThread.Terminate;
    Stopped := True;
  end;
  
  end.
  </code></pre>