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

  • Live Event Date: August 19, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You deployed your app with the Bluemix PaaS and it's gaining some serious traction, so it's time to make some tweaks. Did you design your application in a way that it can scale in the cloud? Were you even thinking about the cloud when you built the app? If not, chances are your app is going to break. Check out this upcoming webcast to learn various techniques for designing applications that will scale successfully in Bluemix, for the …

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds