Changeset 154 for MicroThreading/Demo/UMainForm.pas
- Timestamp:
- Jan 27, 2011, 2:15:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/Demo/UMainForm.pas
r153 r154 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, ExtCtrls, Spin, UMicroThreading, Coroutine,DateUtils, UPlatform;9 ComCtrls, ExtCtrls, Spin, UMicroThreading, DateUtils, UPlatform; 10 10 11 11 type … … 67 67 procedure Worker(MicroThread: TMicroThread); 68 68 procedure WorkerDoWrite; 69 procedure WorkerSubRoutine; 69 70 public 70 71 Iterations: Integer; 71 Scheduler: TMicroThreadScheduler;72 72 end; 73 73 … … 85 85 procedure TMainForm.FormCreate(Sender: TObject); 86 86 begin 87 Scheduler := TMicroThreadScheduler.Create;88 87 DoubleBuffered := True; 89 88 ListView1.DoubleBuffered := True; … … 97 96 if ButtonSchedulerStartStop.Caption = 'Start scheduler' then begin 98 97 ButtonSchedulerStartStop.Caption := 'Stop scheduler'; 99 Scheduler.ThreadPoolSize := SpinEdit2.Value;100 Scheduler.Active := True;98 MainScheduler.ThreadPoolSize := SpinEdit2.Value; 99 MainScheduler.Active := True; 101 100 end else begin 102 101 ButtonSchedulerStartStop.Caption := 'Start scheduler'; 103 Scheduler.Active := False;102 MainScheduler.Active := False; 104 103 end; 105 104 end; … … 169 168 //Scheduler.FMicroThreads.Clear; 170 169 for I := 0 to SpinEdit1.Value - 1 do 171 Scheduler.AddMethod(Worker);170 MainScheduler.AddMethod(Worker); 172 171 end; 173 172 … … 197 196 begin 198 197 try 199 Scheduler.MicroThreadsLock.Acquire;200 Scheduler.MicroThreads.Clear;198 MainScheduler.MicroThreadsLock.Acquire; 199 MainScheduler.MicroThreads.Clear; 201 200 finally 202 Scheduler.MicroThreadsLock.Release;201 MainScheduler.MicroThreadsLock.Release; 203 202 end; 204 203 end; … … 206 205 procedure TMainForm.CheckBoxUseMainThreadChange(Sender: TObject); 207 206 begin 208 Scheduler.UseMainThread := CheckBoxUseMainThread.Checked;207 MainScheduler.UseMainThread := CheckBoxUseMainThread.Checked; 209 208 end; 210 209 211 210 procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); 212 211 begin 213 Scheduler.Active := False;212 MainScheduler.Active := False; 214 213 end; 215 214 216 215 procedure TMainForm.FormDestroy(Sender: TObject); 217 216 begin 218 Scheduler.Free;217 MainScheduler.Free; 219 218 end; 220 219 … … 227 226 begin 228 227 try 229 Scheduler.MicroThreadsLock.Acquire;230 if Item.Index < Scheduler.MicroThreads.Count then231 with TMicroThread( Scheduler.MicroThreads[Item.Index]) do begin228 MainScheduler.MicroThreadsLock.Acquire; 229 if Item.Index < MainScheduler.MicroThreads.Count then 230 with TMicroThread(MainScheduler.MicroThreads[Item.Index]) do begin 232 231 Item.Caption := IntToStr(Id); 233 232 Item.SubItems.Add(Name); … … 240 239 end; 241 240 finally 242 Scheduler.MicroThreadsLock.Release;241 MainScheduler.MicroThreadsLock.Release; 243 242 end; 244 243 end; … … 246 245 procedure TMainForm.SpinEdit2Change(Sender: TObject); 247 246 begin 248 Scheduler.ThreadPoolSize := SpinEdit2.Value;247 MainScheduler.ThreadPoolSize := SpinEdit2.Value; 249 248 end; 250 249 … … 256 255 procedure TMainForm.TimerRedrawTimer(Sender: TObject); 257 256 begin 258 if ListView1.Items.Count <> Scheduler.MicroThreadCount then259 ListView1.Items.Count := Scheduler.MicroThreadCount;257 if ListView1.Items.Count <> MainScheduler.MicroThreadCount then 258 ListView1.Items.Count := MainScheduler.MicroThreadCount; 260 259 ListView1.Items[-1]; 261 260 ListView1.Refresh; 262 261 Label2.Caption := DateTimeToStr(NowPrecise) + ' ' + 263 262 FloatToStr(Frac(NowPrecise / OneSecond)); 264 Label9.Caption := IntToStr( Scheduler.ThreadPoolCount);265 Label10.Caption := IntToStr( Scheduler.MicroThreadCount);263 Label9.Caption := IntToStr(MainScheduler.ThreadPoolCount); 264 Label10.Caption := IntToStr(MainScheduler.MicroThreadCount); 266 265 end; 267 266 … … 271 270 ButtonAddWorkers.Click; 272 271 ButtonSchedulerStartStop.Click; 272 end; 273 274 procedure TMainForm.WorkerSubRoutine; 275 begin 276 MTSleep(1 * OneMillisecond); 273 277 end; 274 278 … … 287 291 // FloatToStr(ExecutionTime)); 288 292 Completion := I / Iterations; 289 // Sleep(1 * Id * OneMillisecond);293 //MTSleep(1 * Id * OneMillisecond); 290 294 Yield; 295 WorkerSubRoutine; 291 296 end; 292 297 end;
Note:
See TracChangeset
for help on using the changeset viewer.