Results 1 to 4 of 4

Thread: [RESOLVED] Timer Control - ?????

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Resolved [RESOLVED] Timer Control - ?????

    I have just been playing with the timer control.

    When I use an interval of 10 and then in the tick event add 0.01 to a total and then have another timer interval set to 1 and add 0.001 to a total in the tick event I get different totals why?

    Is it the processor speed or is it me that’s got it wrong

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Timer Control - ?????

    Hi,
    don't depend on timers to give you accuracy down to that level - they just won't cut it.
    10 is every 10 milliseconds, and 1 is every millisecond.

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2006
    Posts
    612

    Re: Timer Control - ?????

    Pete says: Timers just won't cut it, got ya

    Many thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Timer Control - ?????

    Firstly, the Windows.Forms.Timer and Timers.Timer classes are not controls. They are both components. They inherit, either directly or indirectly, the Component class, which means they support the form designer, but they are not derived from the Control class. Note that the Control class itself inherits the Component class, so all controls are components, hence they support the form designer, but not all components are controls.

    Timers do do a job but, as petevick says, they aren't accurate to that resolution. The Windows.Forms.Timer raises its Tick event in the UI thread. Any thread can only do one thing at a time. If your UI thread is busy then execution of the Tick event handler will have to wait until it's free. That also means that if you have 11 Tick events every 10 milliseconds your UI is going to be pretty sluggish because it will be spend so much time processing Tick events.

    The Timers.Timer can raise its Elapsed events in the UI thread or a worker thread. That can make it more accurate but it also means that you have to use extra code if you want to access controls from the event handler. Unfortunately the Timers.Timer is not available in the CF.

    The Threading.Timer class is not a component but it is supported on the CF. It's fairly different to the other two though, and I've never used it so I can't say more.

    As I'm fond of posting, always read the documentation for the types and members you're using, especially if they don't work the way you expect. This is from the MSDN help topic for the Windows.Forms.Timer class:
    The Windows Forms Timer component is single-threaded, and is limited to an accuracy of 55 milliseconds. If you require a multithreaded timer with greater accuracy, use the Timer class in the System.Timers namespace.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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