• 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。

  • 相关阅读:
    MySQL 字符串与时间操作函数
    Redis消息订阅,事务,modules
    Redis数据结构
    Redis数据类型String
    Redis
    网络协议原理和lvs三种模型,调度算法和keepalived
    TCP连接状态,SYNC_RECV,CLOSE_WAIT,TIME_WAIT
    arp_ignore和arp_announce
    JMH和Disrupter
    容器CopyOnWriteList,ConcurrentHashMap,ConcurrentSkipListMap,BlockingQueue
  • 原文地址:https://www.cnblogs.com/kinglandsoft/p/13976718.html
Copyright © 2020-2023  润新知