Ignore:
Timestamp:
Jan 24, 2011, 8:49:56 AM (14 years ago)
Author:
george
Message:
  • Added: Scheduler Start and Stop methods.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/UMicroThreading.pas

    r140 r141  
    99  {$IFDEF Windows}Windows,{$ENDIF}
    1010  {$IFDEF Linux}BaseUnix, UnixUtil, Unix,{$ENDIF}
    11   Classes, SysUtils, Contnrs, SyncObjs, DateUtils, Dialogs;
     11  Classes, SysUtils, Contnrs, SyncObjs, DateUtils, Dialogs, Forms;
    1212
    1313type
     
    6666    FExecuteCount: Integer;
    6767    FExecutedCount: Integer;
     68    FTerminated: Boolean;
    6869    function GetMicroThreadCount: Integer;
    6970    procedure Yield(MicroThread: TMicroThread);
     
    7677    destructor Destroy; override;
    7778    function Execute(Count: Integer): Integer;
     79    procedure Start;
     80    procedure Stop;
    7881    property MicroThreadCount: Integer read GetMicroThreadCount;
    7982    property FreeMicroThreadOnFinish: Boolean read FFreeMicroThreadOnFinish
     
    167170destructor TMicroThreadScheduler.Destroy;
    168171begin
     172  FTerminated := True;
    169173  ThreadPool.Free;
    170174  MicroThreads.Free;
     
    179183  Yield(nil);
    180184  Result := FExecutedCount;
     185end;
     186
     187procedure TMicroThreadScheduler.Start;
     188var
     189  Executed: Integer;
     190begin
     191  FTerminated := False;
     192  repeat
     193    Executed := Execute(10);
     194    Application.ProcessMessages;
     195    if Executed = 0 then Sleep(1);
     196  until FTerminated;
     197end;
     198
     199procedure TMicroThreadScheduler.Stop;
     200begin
     201  FTerminated := True;
    181202end;
    182203
Note: See TracChangeset for help on using the changeset viewer.