Dynamic Timer Class

This class allows you to wait a specific time (like Sleep) AND maintain a responsive UserInterface (UI).

screen-shot

It works like a:

  While (Now < waitTill) : DoEvents : Wend

- loop but doesn't eat up all your system time like the above loop.

Why not use the Timer Control?

Well first, the timer control ist limited to a maximum 65 second intreval while this timer can handle intervals up to 2147483647 ms (that's just a bit less that 25 days).

Second: with a timer control it is difficult to so something like this:

   ..code runs ...
   Wait 10Secs
   ... continue code ..

Third: This class has a Cancel method to stop waiting a once.

Why should you use the Timer control?

CWaitNDispatch can do some unpretty things to your callstack when running. When you call wait on a timer object and then call wait on another while the first one is still running, the second one won't return until the "first" one has finnished. (See the example in the form).

Usage:

  • Instantiate an object of the class CWaitNDispatch.
  • Call the "Wait" function with the number of milliseconds you want to wait as parameter.
  • Call "Cancel" to stop waiting

ATTENTION:
When you call Cancel from a messagehandler (i.e. Command1_Click, Form_Unload) the code after the "Wait" call will continue AFTER you leave the message handler!

So don't call cancel in the Unload event because your app will not terminate then.

Call Cancel in QueryUnload and set the Cancel parameter of QueryUnload to true if timer.IsWaiting returns true.

Download Zipped TimerClass (18k)



Comments

  • There is an end to wait

    Posted by Legacy on 06/19/2002 12:00am

    Originally posted by: sandy

    Thanks buddy,

    You really ended my waiting ..to finish the rpoject..
    it works perfect...
    sandy

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Today's competitive marketplace requires the organization to frequently release and deploy applications at the pace of user demands, with reduced cost, risk, and increased quality. This book defines the basics of application release and deployment, and provides best practices for implementation with resources for a deeper dive. Inside you will find: The business and technical drivers behind automated application release and deployment. Evaluation guides for application release and deployment solutions. …

  • Live Event Date: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds