红鱼儿

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。

2020-12-14:

今天升级了Delphi到10.4.1,也是同样的问题。

2021-6-7

kbmMW 5.15.10修正了上面的问题!!!

 

posted on 2020-11-18 10:22  红鱼儿  阅读(241)  评论(0编辑  收藏  举报