• 升级LoadingIndicator


    ChinaCock中的组件CC.LoadingIndicator,有很好的显示效果,以前也写过使用说明,可以去看看

    在使用的过程中,我一般是这样调用:

      CCLoadingIndicator1.ShowLoadingIndicator('正在查询,请稍候...');
      Scheduler.Run(procedure (const AScheduledEvent:IkbmMWScheduledEvent)
                    begin
                         //在线程中执行查询等任务
                    end)
               .SynchronizedAfterRun(procedure (const AScheduledEvent:IkbmMWScheduledEvent)
                                     begin
                                        //线程执行完成,同步主线程,一般同步界面显示 
    CCLoadingIndicator1.HideLoadingIndicator;
    end) .WhenException(procedure (const AException:Exception) begin   CCLoadingIndicator1.HideLoadingIndicator; ApplicationShowException(AException); end) .Activate;

    通过上面的代码,可以看到,配对的使用ShowLoadingIndicator与HideLoadingIndicator,以保证在线程中的任务执行完成后,隐藏掉CCLoadingIndicator的显示,这看起来似乎很完美了,但对于同时发起多个线程的情况下,就不行了。例如下面的代码:

    //发起第一个线程任务
      CCLoadingIndicator1.ShowLoadingIndicator('正在执行第一个任务,请稍候...');
      Scheduler.Run(procedure (const AScheduledEvent:IkbmMWScheduledEvent)
                    begin
                         //在线程中执行查询等任务
                    end)
               .SynchronizedAfterRun(procedure (const AScheduledEvent:IkbmMWScheduledEvent)
                                     begin
                                        //线程执行完成,同步主线程,一般同步界面显示 
                                        CCLoadingIndicator1.HideLoadingIndicator;    
                                     end)
               .WhenException(procedure (const AException:Exception)
                              begin
                                   CCLoadingIndicator1.HideLoadingIndicator;
                                   ApplicationShowException(AException);
                              end)
               .Activate;
    ...
    //发起第二个线程任务
      CCLoadingIndicator1.ShowLoadingIndicator('正在执行第二个任务,请稍候...');
      Scheduler.Run(procedure (const AScheduledEvent:IkbmMWScheduledEvent)
                    begin
                         //在线程中执行查询等任务
                    end)
               .SynchronizedAfterRun(procedure (const AScheduledEvent:IkbmMWScheduledEvent)
                                     begin
                                        //线程执行完成,同步主线程,一般同步界面显示 
                                        CCLoadingIndicator1.HideLoadingIndicator;    
                                     end)
               .WhenException(procedure (const AException:Exception)
                              begin
                                   CCLoadingIndicator1.HideLoadingIndicator;
                                   ApplicationShowException(AException);
                              end)
               .Activate;
    ...

     上面的代码,我只是为了说明问题,所以只是简单的复制出来样子,发起两个线程任务。具体执行起来,不管哪一个任务先完成,都会调用HideLoadingIndicator,让LoadingIndicator不再显示,而这时候,没有执行完的任务还需要LoadingIndicator显示,矛盾就这样产生了。

    经改后升级的LoadingIndicator,完美的解决了这个问题!

    代码中发起线程任务是用的kbmMW Scheduler Framework。我有译过这方面的文章,可以去查阅。

  • 相关阅读:
    CentOS5.6下SVN的安装
    在servlet中的init方法中使用getInitParameter方法空指针错误
    Linux iostat监测IO状态【转】
    自己实现一个list比较器 实现Comparator()接口
    一些常用的随机实现
    java里null强转为某个类会报错吗?
    java游戏服务器简单工厂模式
    起个头!准备写一个 设计模式系列
    HashMap根据value值排序
    java游戏服务器 策略+简单工厂
  • 原文地址:https://www.cnblogs.com/kinglandsoft/p/12462777.html
Copyright © 2020-2023  润新知