Changeset 160 for MicroThreading/Demo/UMainForm.pas
- Timestamp:
- Feb 1, 2011, 10:06:01 AM (14 years ago)
- Location:
- MicroThreading
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading
- Property svn:ignore
-
old new 1 1 lib 2 backup
-
- Property svn:ignore
-
MicroThreading/Demo
- Property svn:ignore
-
old new 2 2 lib 3 3 Demo.exe 4 backup
-
- Property svn:ignore
-
MicroThreading/Demo/UMainForm.pas
r159 r160 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 9 ComCtrls, ExtCtrls, Spin, UMicroThreading, DateUtils, UPlatform, 10 UMicroThreadList ;10 UMicroThreadList, UThreadEx; 11 11 12 12 type … … 29 29 Button3: TButton; 30 30 Button4: TButton; 31 Button5: TButton; 31 32 ButtonAddWorkers: TButton; 32 33 ButtonClearMicroThreads: TButton; … … 72 73 procedure Button3Click(Sender: TObject); 73 74 procedure Button4Click(Sender: TObject); 75 procedure Button5Click(Sender: TObject); 74 76 procedure ButtonSchedulerStartStopClick(Sender: TObject); 75 77 procedure Button2Click(Sender: TObject); … … 92 94 private 93 95 MicroThreadList: TMicroThreadList; 96 LastException: Exception; 97 LastExceptionSender: TObject; 94 98 procedure WorkerSubRoutine; 99 procedure ShowException(Sender: TObject; E: Exception); 100 procedure DoShowException; 95 101 public 96 102 DoWriteToMemo: Boolean; 97 103 DoSleep: Boolean; 104 RaiseException: Boolean; 98 105 SleepDuration: Integer; 99 106 DoWaitForEvent: Boolean; … … 121 128 Event := TMicroThreadEvent.Create; 122 129 MicroThreadList := TMicroThreadList.Create(Self); 130 UMicroThreading.ExceptionHandler := ShowException; 123 131 end; 124 132 … … 150 158 begin 151 159 MicroThreadList.Form.Show; 160 end; 161 162 procedure TMainForm.Button5Click(Sender: TObject); 163 begin 164 RaiseException := True; 152 165 end; 153 166 … … 335 348 end; 336 349 350 procedure TMainForm.ShowException(Sender: TObject; E: Exception); 351 begin 352 LastException := E; 353 LastExceptionSender := Sender; 354 if MainThreadID <> ThreadID then 355 TThread.Synchronize(TThreadEx.CurrentThread, DoShowException) 356 else DoShowException; 357 end; 358 359 procedure TMainForm.DoShowException; 360 begin 361 ShowMessage('Exception "' + LastException.Message + '" in class "' + 362 LastExceptionSender.ClassName + '"') 363 end; 364 337 365 procedure TWorker.Execute; 338 366 var … … 346 374 if MainForm.DoWaitForEvent then MainForm.Event.WaitFor(MainForm.WaitForEventDuration * OneMillisecond); 347 375 if MainForm.DoSleep then MTSleep(MainForm.SleepDuration * OneMillisecond); 376 if MainForm.RaiseException then begin 377 MainForm.RaiseException := False; 378 raise Exception.Create('Exception from microthread'); 379 end; 348 380 //WorkerSubRoutine; 349 381 Completion := I / MainForm.Iterations;
Note:
See TracChangeset
for help on using the changeset viewer.