1. 程式人生 > 實用技巧 >kbmMW 5.13.00 Scheduler不執行SynchronizedAfterRun

kbmMW 5.13.00 Scheduler不執行SynchronizedAfterRun

kbmMW 5.13.00釋出了,升級後遇到這個問題,SynchronizedAfterRun不執行。

procedure TForm4.Button1Click(Sender: TObject);
begin
   Text1.Text:='執行緒在執行中';
   Scheduler.Run(procedure
                 var
                    i:Integer;
                 begin
                   for I := 1 to 10 do
                      sleep(100
); end) .SynchronizedAfterRun(procedure begin Text1.Text:='執行緒執行完成,執行SynchronizedAfterRun方法。' end) .Activate(True); end;

這段程式碼,做為測試專案執行,沒有問題,但類似的寫法在我實際生產的專案中,則不執行SynchronizeAfterRun方法。本想給作者寫個demo專案重顯問題,無耐又無法重顯!

給作者反應,下面是他的回覆:

在BBS上回復:

(replied directly by email)
SynchronizedAfterRun now use Queue rather than Synchronize, to be sure it will not deadlock in some situations, where the main thread is blocked.
To ensure the after run is executed, the mainthread must allow for execution from time to time.

(直接通過電子郵件回覆)
現在,SynchronizedAfterRun使用Queue而不是Synchronize,以確保在某些情況下(主執行緒被阻塞)它不會死鎖。
為了確保執行後執行,主執行緒必須不時允許執行。

郵件回覆:

It queues the sync request to run, which means that you must give your
GUI a chance to update for the code in the SynchronizedAfterRun to be
allowed to run.

它對要執行的同步請求進行排隊,這意味著您必須給GUI一個機會來更新要允許執行SynchronizedAfterRun中的程式碼。

看了回覆,不知道如何寫程式碼。

對比分析一下5.13與版本5.12的區別:

試著將Queue替換為Synchronize,執行,應用正常了!

Delphi 10.3.3 win32

又試著解決這個問題,終無果!只好改成Synchronize。