Changeset 271
- Timestamp:
- Aug 30, 2011, 3:47:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UThreading.pas
r267 r271 89 89 TTermThread = class(TListedThread) 90 90 private 91 FOnFinished: TNotifyEvent; 91 92 public 92 93 State: TTermThreadState; … … 94 95 Method: TMethodCall; 95 96 procedure Execute; override; 97 property OnFinished: TNotifyEvent read FOnFinished write FOnFinished; 96 98 end; 97 99 … … 109 111 110 112 procedure RunInThread(Method: TMethodCall); 113 procedure RunInThreadAsync(Method: TMethodCall; Callback: TNotifyEvent = nil); 111 114 procedure Synchronize(Method: TMethodCall); 112 115 … … 124 127 Thread := TTermThread.Create(True); 125 128 Thread.FreeOnTerminate := False; 129 Thread.Method := Method; 126 130 Thread.Resume; 127 Thread.Method := Method;128 131 while (Thread.State = ttsRunning) or (Thread.State = ttsReady) do begin 129 132 if MainThreadID = ThreadID then Application.ProcessMessages; … … 137 140 end; 138 141 142 procedure RunInThreadAsync(Method: TMethodCall; Callback: TNotifyEvent = nil); 143 var 144 Thread: TTermThread; 145 begin 146 try 147 Thread := TTermThread.Create(True); 148 Thread.FreeOnTerminate := True; 149 Thread.Method := Method; 150 Thread.OnFinished := CallBack; 151 Thread.Resume; 152 //if Thread.State = ttsExceptionOccured then 153 // raise Exception.Create(Thread.ExceptionMessage); 154 finally 155 end; 156 end; 157 139 158 procedure Synchronize(Method: TMethodCall); 140 159 var … … 151 170 end; 152 171 153 { TVirtualThread }154 155 172 156 173 { TThreadList } … … 186 203 end; 187 204 188 { TVirtualThread }189 190 191 205 { TListedThread } 192 206 … … 324 338 Method; 325 339 State := ttsFinished; 340 if Assigned(FOnFinished) then 341 FOnFinished(Self); 326 342 except 327 on E: Exception do 328 if Assigned(OnException) then begin 343 on E: Exception do begin 344 ExceptionMessage := E.Message; 345 State := ttsExceptionOccured; 346 if Assigned(OnException) then 329 347 OnException(FThread, E); 330 ExceptionMessage := E.Message; 331 State := ttsExceptionOccured; 332 end; 348 end; 333 349 end; 334 350 end;
Note:
See TracChangeset
for help on using the changeset viewer.