zoukankan      html  css  js  c++  java
  • Using Timer

    Using Timer

    If you want perform a periodic task you can use batch processing, but there is another option to perform local fast periodic tasks - timers.

    You can call the setTimeOut function in forms or client-side classes like this:

    this.setTimeOut("updateRealTime", 1000, FALSE);

    where

    • "updateRealTime" - Name of method to call.
    • 1000 - wait time in milliseconds
    • true - means that time should only be measured while the program is idle.

    This example is taken from tutorial_Timer form

    Lets see at the updateRealTime source:

    void updateRealTime()
      {
        _realTime.value(timeNow());
        _realTimer = this.setTimeOut("updateRealTime", 1000, FALSE);
      }

    it performes some useful action (realTime.value(timeNow());) and then sets the timeout again, so the action will be performed every second.

    Another pattern of using timers is to perform something in the background or as an interruptable task. The clearest example is SysAotFind form which performs a search through the AOT.

    The pattern is as follows:

    • declare a "stop flag" in your object
    • divide your task into small iterative steps
    • execute each step in the timeout function
    • set the timeout again at the end of the timeout function, if the stop flag is not set
    • when user presses the stop button, set the stop flag to true. Execution will stop at the end of the next cycle.

    see \Forms\SysAotFind\Methods\nextTreeNode for example

  • 相关阅读:
    [bzoj 2151]种树(贪心)
    [bzoj 1026]windy数(数位DP)
    [BZOJ2038]小Z的袜子(莫队算法)
    spark调优
    从底层谈WebGIS 原理设计与实现(一):开篇
    css兼容性记录
    H5新标签
    AMD 与CMD
    rem 响应 js函数
    SVN服务器搭建和使用(一)
  • 原文地址:https://www.cnblogs.com/perock/p/2352995.html
Copyright © 2011-2022 走看看