Changeset 166 for MicroThreading/Demo/UMainForm.pas
- Timestamp:
- Feb 9, 2011, 1:35:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/Demo/UMainForm.pas
r164 r166 33 33 Button4: TButton; 34 34 Button5: TButton; 35 Button6: TButton; 35 36 ButtonAddWorkers: TButton; 36 37 ButtonClearMicroThreads: TButton; … … 77 78 procedure Button4Click(Sender: TObject); 78 79 procedure Button5Click(Sender: TObject); 80 procedure Button6Click(Sender: TObject); 79 81 procedure ButtonSchedulerStartStopClick(Sender: TObject); 80 82 procedure Button2Click(Sender: TObject); … … 105 107 procedure ShowException(Sender: TObject; E: Exception); 106 108 procedure DoShowException; 109 procedure MethodWorker; 107 110 public 108 111 DoWriteToMemo: Boolean; … … 171 174 begin 172 175 RaiseException := True; 176 end; 177 178 procedure TMainForm.Button6Click(Sender: TObject); 179 var 180 I: Integer; 181 begin 182 //Scheduler.FMicroThreads.Clear; 183 for I := 0 to SpinEdit1.Value - 1 do begin 184 MainScheduler.AddMethod(MethodWorker, False); 185 end; 173 186 end; 174 187 … … 363 376 ShowMessage('Exception "' + LastException.Message + '" in class "' + 364 377 LastExceptionSender.ClassName + '"') 378 end; 379 380 procedure TMainForm.MethodWorker; 381 var 382 I: Integer; 383 Q: Integer; 384 begin 385 for I := 0 to MainForm.Iterations - 1 do begin 386 Q := 0; 387 while Q < 100000 do Inc(Q); 388 if MainForm.DoWriteToMemo then 389 MainForm.Memo1.Lines.Add(IntToStr(GetCurrentMicroThread.Id) + ': ' + IntToStr(Trunc(GetCurrentMicroThread.Completion * 100)) + ' %'); 390 if MainForm.DoWaitForEvent then MainForm.Event.WaitFor(MainForm.WaitForEventDuration * OneMillisecond); 391 if MainForm.DoSleep then MTSleep(MainForm.SleepDuration * OneMillisecond); 392 if MainForm.RaiseException then begin 393 MainForm.RaiseException := False; 394 raise Exception.Create('Exception from microthread'); 395 end; 396 if MainForm.DoCriticalSection then begin 397 try 398 MainForm.Lock.Acquire; 399 MTSleep(MainForm.CriticalSectionSleepDuration * OneMillisecond); 400 finally 401 MainForm.Lock.Release; 402 end; 403 end; 404 //WorkerSubRoutine; 405 GetCurrentMicroThread.Completion := I / MainForm.Iterations; 406 GetCurrentMicroThread.Yield; 407 end; 365 408 end; 366 409
Note:
See TracChangeset
for help on using the changeset viewer.