Results 1 to 7 of 7

Thread: Timers and the code inside them

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Timers and the code inside them

    Hey Guys,

    I've been using some timers in an application I'm developing. However, I've been noticing some hiccups in the softwares performance. In an article I was reading on Timer, its stated I should not put too much code in a Timer event. How much is too much?

    Thanks,
    Brock

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Timers and the code inside them

    To be honest, Timers shouldn't be used at all, even though they are easy to use. They are slow, inconsistant, inaccurate, and if your app is used on Windows XP, they go 10 times faster than usual, making them REALLY inaccurate and inconsistant. And it gets worse the more timers you use.

    Using managed loops is the way to go. I'll upload a project for you in 30 minutes.

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Timers and the code inside them

    I should not put too much code in a Timer event. How much is too much?
    The code that is going to run the the Timer Event will run until it is finished and it will block all other code including subsequent calls to the timer.

    So, the first rule is don't put code in there that will run for a significant fraction of the timer interval.

    For example, if your timer interval is 100ms and your code takes 100ms to run then nothing in your code will get a chance to run except the timer. if the code takes 50ms to run then the rest of you app will be blocked for 50% of the time i.e. users can't interact with the app 50% of the time.

    Since it's not a good idea to use DoEvents in a timer, any code that is going to block for a noticable period should be put elsewhere with DoEvents in it.

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Re: Timers and the code inside them

    Managed loops eh? I'm curious to see this project, I'd really like to take out all the Timer events in my application. The Timers cannot be trusted

    Brock

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Timers and the code inside them

    The Timers cannot be trusted
    Oh, those Evil Timers!
    Timers can be trusted to behave as they were designed to and provide a convient way to do many tasks. Just don't try to use them in a manner they were not intended to be used.

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Timers and the code inside them

    Another thing you should know. About the only thing that's good about timers is the fact that it maintains low CPU usage and its ease of use. That's all. Other than that, they are horrible. And when multiple timers are firing off all at once, that's when slow down and incosistancy really get noticable.

    Here ya go. A nice example of a managed loop. Locked at 60 FPS (frames per second)
    Attached Files Attached Files

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Timers and the code inside them

    brockmasterflex,

    Take a look in my signature for Help with Timers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width