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

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Not long ago, security was viewed as one of the biggest obstacles to widespread adoption of cloud-based deployments for enterprise software solutions. However, the combination of advancing technology and an increasing variety of threats that companies must guard against is rapidly turning the tide. Cloud vendors typically offer a much higher level of data center and virtual system security than most organizations can or will build out on their own. Read this white paper to learn the five ways that cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds