logo
down
shadow

How to pause a timer created with CreateTimerQueueTimer


How to pause a timer created with CreateTimerQueueTimer

By : TopDevelopr111
Date : October 23 2020, 06:10 PM
This might help you I believe you can call ChangeTimerQueueTimer and set the _In_ ULONG Period to 0. Where the _In_opt_ HANDLE TimerQueue argument will be NULL and the _Inout_ HANDLE Timer will be the HANDLE retrieved from CreateTimerQueueTimer. This will execute the callback in the timer just once and stop. If you want to reactivate the timer you can ChangeTimerQueueTimer again with the same handle providing a period greater than 0 to run periodically. There isn't specifically an API to suspend the timer but preventing it from running periodically should be the equivalent in your case. Just note that your callback will get hit once after calling ChangeTimerQueueTimer before "suspending".
code :


Share : facebook icon twitter icon
Schedule Update One in ccTouchesMoved/Pause Timer/Resume Timer - Cocos2d

Schedule Update One in ccTouchesMoved/Pause Timer/Resume Timer - Cocos2d


By : user39460
Date : March 29 2020, 07:55 AM
Any of those help I'm just trying to schedule an update method once in ccTouchesMoved, but when I add this , To pause the timer I just used
code :
[self unschedule:@selector(g:)];
[self schedule:@selector(g:)];
How do you create a more accurate timer in OpenLaszlo than the lz.Timer class that can pause and loop?

How do you create a more accurate timer in OpenLaszlo than the lz.Timer class that can pause and loop?


By : Milind
Date : March 29 2020, 07:55 AM
will be helpful for those in need The following OpenLaszlo timer class I designed will fire more accurately and also has a nice looping feature with pause and reset for ease of use. This code works in OpenLaszlo 4.9.0 SWF10 and DHTML run-times:
code :
<library>

  <!---
  Class: <loopingtimer>
  Extends: <node>

  This class is a looping timer that can be used to call a method to peform
  an action repeatedly after a specified number of milliseconds.

  Override the abstract method reactToTimeChange(theTime) to do something
  useful in your application, theTime will be the time elapsed since the
  timer's last firing, it will be close to the 'timer_resolution' set but
  will be off from about 47ms-78ms in FireFox 2 and 47ms-94ms in IE6
  (see note below for explanation).

  NOTE:

  This class originally used the LzTimer class but it was firing up to 256ms
  late, so this has been replaced with a setTimeout() method and embedded
  JavaScript which is more accurate, but still fires about 59ms late on
  average.

  For this reason the firing times of this class are approximate but will
  probably fire 47ms to 78ms (about 59ms) on average late. As a workaround
  for this problem the timer uses the system time to calculate how much time
  has actually elapsed since the last timer firing and passes the actual time
  elapsed ('theTime') in milliseconds to the abstract 'reactToTimeChange()'
  method.

  -->
  <class name="loopingtimer" extends="node">

    <switch>
      <when property="$as3">
        <passthrough>
          import flash.utils.setTimeout;
        </passthrough>
      </when>
    </switch>

    <!-- *** ATTRIBUTES *** -->

    <!-- Public Attributes -->

    <!---
    @param numnber timer_resolution: number of milliseconds between timer
    firings (default: 40ms)

    Note: OpenLaszlo seems to typically have a lower limit of 47-78
    milliseconds between firings, so setting below this may be useless.
    -->
    <attribute name="timer_resolution" type="number" value="40" />

    <!-- Private Attributes -->

    <!--- @keywords private -->
    <!---
    @param number formertime: used internally to calculate the number of
    elapsed milliseconds since playback was started
    -->
    <attribute name="formertime" type="number" value="0" />

    <!--- @keywords private -->
    <!---
    Used internally for tracking virtual current time in milliseconds
    for pause functionality.
    -->
    <attribute name="currenttime" type="number" value="0" />

    <!--- @keywords private -->
    <!--- @param string timer_state: 'PAUSED' | 'COUNTING' -->
    <attribute name="timer_state" type="string" value="PAUSED" />


    <!-- *** METHODS *** -->


    <!-- Public Methods -->


    <!--- @keywords abstract -->
    <!---
    ABSTRACT METHOD: overwrite to do something useful in your program

    @param number theTime: the time in milliseconds elapsed since playback
    was  started
    -->
    <method name="reactToTimeChange" args="theTime">
      if ($debug){
        Debug.write('WARNING: reactToTimeChange(): This is an abstract method that should be overridden to do something useful in your application');
        Debug.write('reactToTimeChange(): Time elapsed since last firing in milliseconds: '+theTime);
      }
    </method>

    <!--- Start Timer (Note: This will reset timer to 0) -->
    <method name="startTimer">
      this.setAttribute('timer_state', 'COUNTING');
      var now = new Date();
      var rawTime = now.getTime();
      this.setAttribute('formertime', rawTime);

      this.doForTime();
    </method>

    <!--- Pauses timer at current time -->
    <method name="pauseTimer">
      this.setAttribute('timer_state', 'PAUSED');
    </method>

    <!--- Resumes timer from time it is paused at -->
    <method name="unpauseTimer">
      this.setAttribute('timer_state', 'COUNTING');
      var now = new Date();
      var rawTime = now.getTime();
      this.setAttribute('formertime', rawTime-this.currenttime);
      this.repeat();
    </method>

    <!--- Stop Timer - stops timer and resets to 0  -->
    <method name="stopTimer">
      this.pauseTimer();
      this.resetTimer();
    </method>

    <!--- Resets Timer to 0 -->
    <method name="resetTimer">
      this.setAttribute('formertime', 0);
      this.setAttribute('currenttime', 0);
    </method>

    <!---
    Seeks to the given time in milliseconds.

    @param number(int) iTimeMs: the time to seek to
    -->
    <method name="seekToTime" args="iTimeMs">
      this.setAttribute('currenttime', Math.floor(iTimeMs));
    </method>

    <!-- Private Methods -->


    <!--- @keywords private -->
    <!---
    Called Internally By Timer

    @param number theTime: the actual time in milliseconds that has passed
    since the last timer firing (will usually be 16-100ms more than timer
    firing interval)
    -->
    <method name="doForTime">

      // Prevent Timer Incrementing When Paused
      if (this.timer_state == 'PAUSED')
        return;

      var now = new Date();

      var rawTime = now.getTime();

      if (this.formertime != 0)
        var currentTime = rawTime - this.formertime;

      this.setAttribute('currenttime', currentTime);

      // Call Abstract Method:
      this.reactToTimeChange(currentTime);

      this.repeat();

    </method>

    <!--- @keywords private -->
    <!---
    Used internally for timer looping.
    -->
    <method name="repeat">

      // This function uses an embedded JavaScript function which
      // can be called via the standard JavaScript setTimeout()
      // method which results in more accurate timer firing then the
      // standard OpenLaszlo LzTimer() class. LzTimer() fired up to
      // 256ms late, while setTimeout() usually fires from
      // only 47ms-78ms

      var f = function(){
        doForTime();
      }

      setTimeout(f, this.timer_resolution);
    </method>

  </class>

</library>
How can one do start - pause - continue - pause - continue - pause with the threading.timer?

How can one do start - pause - continue - pause - continue - pause with the threading.timer?


By : Passwhl
Date : March 29 2020, 07:55 AM
hop of those help?
I have wrote def fin(self): self.schedule.cancel() but it is not stopped Why?
code :
class Scheduling(threading.Thread):
    def __init__(self):
            self.schedule = None
            threading.Thread.__init__(self)

    def run(self):                                
            self.schedule = threading.Timer(2, self.run)
            self.schedule.start()

    def cancel(self):
            self.schedule.cancel()
A click to start the countdown timer and a second one to Pause the timer in the same button

A click to start the countdown timer and a second one to Pause the timer in the same button


By : cuongroman
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can add an additional state variable isActive that keeps track of if your timer is active or not and choose what function to call when clicking the button based on that.
Example
code :
class Timer extends React.Component {
  state = {
    isActive: false,
    secondsElapsed: 1800000 / 1000 //time in seconds
  };

  getHours() {
    return ("0" + Math.floor(this.state.secondsElapsed / 3600)).slice(-2);
  }

  getMinutes() {
    return ("0" + Math.floor((this.state.secondsElapsed % 3600) / 60)).slice(
      -2
    );
  }

  getSeconds() {
    return ("0" + (this.state.secondsElapsed % 60)).slice(-2);
  }

  startTime = () => {
    this.setState({ isActive: true });
    
    this.countdown = setInterval(() => {
      this.setState(({ secondsElapsed }) => ({
        secondsElapsed: secondsElapsed - 1
      }));
    }, 1000);
  };

  resetTime = () => {
    clearInterval(this.countdown);
    this.setState({
      secondsElapsed: 1800000 / 1000,
      isActive: false
    });
  };

  pauseTime = () => {
    clearInterval(this.countdown);
    this.setState({ isActive: false });
  };

  render() {
    return (
      <div className="App">
        <div className="timer-container">
          <span className="bloc-timer"> {this.getHours()}</span>
          <span className="bloc-timer"> :{this.getMinutes()}</span>
          <span className="bloc-timer"> :{this.getSeconds()}</span>
        </div>
        <div>
          <button
            onClick={this.state.isActive ? this.pauseTime : this.startTime}
          >
            Start/Pause
          </button>
          <button onClick={this.resetTime}>Reset</button>
        </div>
      </div>
    );
  }
}

ReactDOM.render(<Timer />, document.getElementById("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<div id="root"></div>
How can I use CreateTimerQueueTimer to create a high resolution timer in C#?

How can I use CreateTimerQueueTimer to create a high resolution timer in C#?


By : user3780072
Date : March 29 2020, 07:55 AM
this will help Here is a link to a C# wrapper for CreateTimerQueueTimer:
http://social.msdn.microsoft.com/Forums/en-CA/csharpgeneral/thread/822aed2d-dca0-4a8e-8130-20fab69557d2
Related Posts Related Posts :
  • dynamic memory for 2D char array
  • C compiler producing lightweight executeables
  • Cannot Open Shared Object cygmpfr-1.dll
  • How to access a structure member in a function that get it as void* type?
  • Replace for loop with formula
  • how to find if stack increases upwards or downwards?
  • Why does my homespun sizeof operator need a char* cast?
  • Setting exit status when creating core dump
  • Signal Handling in C
  • How to implement B+ Tree for file systems?
  • Stack storage at function call
  • Manipulate the Clipboard in C on Mac OS X
  • Problem with writing a hexadecimal string
  • Why does this code read all ' ' for the anything after the 4th character?
  • GUI for linux c
  • Where do I put all these function-like #defines, in C?
  • Padding in 24-bits rgb bitmap
  • how to acess and change variable of kernel space from user space
  • Can a conforming C implementation #define NULL to be something wacky
  • send() always interrupted by EPIPE
  • Socket Select with empty fd set
  • Coding self similar fractals in computer graphics using C
  • Forking with Pipes
  • sscanf + c99 not working on some platforms?
  • Problem with C function of type char pointer, can someone explain?
  • Macros in C.... please give the solution
  • Unix Piping using Fork and Dup
  • Any difference between these two while loops?
  • Hashtable implementation for C
  • Problems with Linked List in C
  • Stack Allocation in C
  • Random function stuck on one number
  • printf following zeros to a certain degree
  • Measuring CPU clocks consumed by a process
  • How is a CRC32 checksum calculated?
  • Tips on redefining a register bitfield in C
  • Converting a program from c to bash script
  • Static library not included in resulting LLVM executable
  • What is the meaning of "wild pointer" in C?
  • Reading DWORD from binary file
  • Efficient way to find divisibility
  • Whats the fastest, portable way to hash pointers we know are pointer aligned to a fixed size int?
  • Why does my summation program behaves weird?
  • How to determine values saved on the stack?
  • Thread scheduling C
  • C - converting to 2s complement
  • wireless networks c program
  • From where does the uboot get the information about flash, RTC, RAM in uboot/kernel development
  • printf behaviour in C
  • Measure size and way-order of L1 and L2 caches
  • Efficient copy of entire directory
  • Efficient way to create/unpack large bitfields in C?
  • getnameinfo prototype asks for sockaddr not sockaddr_in?
  • Linked List Sorting with Strings In C
  • Typecasting a floating value or using the math.h floor* functions?
  • Problem implementing sorting algorithm in C with an array of structs
  • How to copy a ram_base file to disk efficiently
  • How to fix casting a pointer to an integer?
  • How to round floating point numbers to the nearest integer in C?
  • PIC C - Sending 200 values over USB, but it only sends 25 or so of them
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk