Changeset 135 for Microthreading/Demo/umainform.pas
- Timestamp:
- Jan 23, 2011, 8:04:49 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Microthreading/Demo/umainform.pas
r134 r135 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, UMicroThreading, Coroutine;9 ComCtrls, ExtCtrls, UMicroThreading, Coroutine, DateUtils; 10 10 11 11 type … … 26 26 ListView1: TListView; 27 27 Memo1: TMemo; 28 Timer1: TTimer; 28 29 procedure Button1Click(Sender: TObject); 29 30 procedure Button2Click(Sender: TObject); … … 31 32 procedure FormCreate(Sender: TObject); 32 33 procedure FormDestroy(Sender: TObject); 34 procedure Timer1Timer(Sender: TObject); 33 35 private 34 36 procedure Worker(MicroThread: TMicroThread); … … 65 67 begin 66 68 Scheduler := TMicroThreadScheduler.Create; 69 Scheduler.FreeMicroThreadOnFinish := False; 67 70 Test := TTest.Create; 68 71 end; … … 74 77 for I := 0 to 1 do 75 78 Scheduler.Add('Worker', Worker); 76 Scheduler.Start; 79 repeat 80 Scheduler.Start; 81 Application.ProcessMessages; 82 Sleep(1); 83 until Scheduler.MicroThreadCount = 0; 77 84 end; 78 85 … … 141 148 end; 142 149 150 procedure TForm1.Timer1Timer(Sender: TObject); 151 var 152 I: Integer; 153 NewItem: TListItem; 154 begin 155 try 156 ListView1.BeginUpdate; 157 ListView1.Clear; 158 Scheduler.Lock.Acquire; 159 for I := 0 to Scheduler.MicroThreads.Count - 1 do 160 with TMicroThread(Scheduler.MicroThreads[I]) do begin 161 NewItem := ListView1.Items.Add; 162 NewItem.Caption := IntToStr(Id); 163 NewItem.SubItems.Add(Name); 164 NewItem.SubItems.Add(''); 165 NewItem.SubItems.Add(IntToStr(Priority)); 166 NewItem.SubItems.Add(MicroThreadStateText[State]); 167 NewItem.SubItems.Add(FloatToStr(ExecutionTime)); 168 end; 169 finally 170 Scheduler.Lock.Release; 171 ListView1.EndUpdate; 172 end; 173 end; 174 143 175 procedure TForm1.Worker(MicroThread: TMicroThread); 144 176 var … … 149 181 for I := 0 to 10 do begin 150 182 Memo1.Lines.Add(InttoStr(Id) + ': ' + IntToStr(I)); 151 SysUtils.Sleep(10 * Id); 152 Yield; 183 Sleep(100 * Id * OneMillisecond); 153 184 end; 154 185 end;
Note:
See TracChangeset
for help on using the changeset viewer.