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

  • Savvy enterprises are discovering that the cloud holds the power to transform IT processes and support business objectives. IT departments can use the cloud to redefine the continuum of development and operations—a process that is becoming known as DevOps. Download the Executive Brief DevOps: Why IT Operations Managers Should Care About the Cloud—prepared by Frost & Sullivan and sponsored by IBM—to learn how IBM SmartCloud Application services provide a robust platform that streamlines …

  • In this on-demand webcast, Oracle ACE and Toad Product Architect Bert Scalzo discusses 10 powerful and hidden features in Toad® that help increase your productivity and DB performance. Watch this webcast today.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds