Updated Version of TThread.Synchronize for Delphi |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
http://homepages.borland.com/strefethen/ http://homepages.borland.com/strefethen/info/ThreadInfo.htm Updated Version of TThread.Synchronize for Delphi 6.0 This is fixed in Update 1 To use this code you will need to recompile Delphi6\source\rtl\common\Classes.pas. I would suggest the following if you absolutely require this fix. Note: This will only work if your application does not use packages. If your application does require packaged then you will have to wait for the release of the update. 1. Copy Delphi6\source\rtl\common\Classes.pas to Delphi6\lib 2. Open Delphi6\lib\Classes.pas in the IDE 3. Search for TThread.Synchronize 4. Replace it with the version below 5. Recompile your application // This code is for Delphi 6.0 only, if your application requires packages // you will have to wait for the update. procedure TThread.Synchronize(Method: TThreadMethod); var SyncProc: TSyncProc; begin if GetCurrentThreadID = MainThreadID then Method else begin {$IFDEF MSWINDOWS} SyncProc.Signal := CreateEvent(nil, True, False, nil); try {$ENDIF} {$IFDEF LINUX} FillChar(SyncProc, SizeOf(SyncProc), 0); // This also initializes the cond_var {$ENDIF} EnterCriticalSection(ThreadLock); try FSynchronizeException := nil; FMethod := Method; SyncProc.Thread := Self; SyncList.Add(@SyncProc); ProcPosted := True; if Assigned(WakeMainThread) then WakeMainThread(Self); {$IFDEF MSWINDOWS} LeaveCriticalSection(ThreadLock); try WaitForSingleObject(SyncProc.Signal, INFINITE); finally EnterCriticalSection(ThreadLock); end; {$ENDIF} {$IFDEF LINUX} pthread_cond_wait(SyncProc.Signal, ThreadLock); {$ENDIF} finally LeaveCriticalSection(ThreadLock); end; {$IFDEF MSWINDOWS} finally CloseHandle(SyncProc.Signal); end; {$ENDIF} if Assigned(FSynchronizeException) then raise FSynchronizeException; end; end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |