Results 1 to 4 of 4

Thread: [Resolved][2005] Timer Question

  1. #1

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    [Resolved][2005] Timer Question

    This is really more of a general .Net Timer object question.

    What happens if the code in the Tick method fails to complete before it's invoked again at the next tick? Are ticks queued and looped so that it will still maintain the timeframe?
    Last edited by vbNeo; May 8th, 2007 at 05:47 AM.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

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

    Re: [2005] Timer Question

    Tick is an event, just like any other. They are raised on the UI thread and the UI thread can only do one thing at a time. If the UI thread is busy when the Tick event is raised then its handlers are not executed until the UI thread becomes available. This is true of all events. Tick is not in any way special in that regard. Now, if the previous Tick event handler is still executing when the next Tick event is raised then that would constitute the UI thread being busy.
    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

  3. #3

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Re: [2005] Timer Question

    Quote Originally Posted by jmcilhinney
    Tick is an event, just like any other. They are raised on the UI thread and the UI thread can only do one thing at a time. If the UI thread is busy when the Tick event is raised then its handlers are not executed until the UI thread becomes available. This is true of all events. Tick is not in any way special in that regard. Now, if the previous Tick event handler is still executing when the next Tick event is raised then that would constitute the UI thread being busy.
    I wasn't aware that Timers were part of the UI thread, I thought they had their own seperate one - but thanks for clarifying .
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

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

    Re: [Resolved][2005] Timer Question

    I'm starting to wonder whether anyone ever reads the MSDN documentation. From the System.Windows.Forms.Timer class topic:
    A Timer is used to raise an event at user-defined intervals. This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread.
    From the System.Timers.Timer class topic:
    The server-based Timer is designed for use with worker threads in a multithreaded environment. Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy than Windows timers in raising the event on time.

    ...

    If you use the Timer with a user-interface element, such as a form or control, assign the form or control that contains the Timer to the SynchronizingObject property, so that the event is marshaled to the user-interface thread.
    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