Results 1 to 4 of 4

Thread: Timers

  1. #1

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Lightbulb Timers

    Do you prefer.....

    To create the timer by code...
    VB Code:
    1. Private t As New System.Timers.Timer(2000)
    Or use the timer control in the form tray?

    and do you use
    VB Code:
    1. tmrMain.Stop
    2. 'or
    3. tmrMain.Enabled = False
    Chris

  2. #2
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: Timers

    Well those two timers aren't the same thing. The control is System.Windows.Forms.Timer, System.Timers.Timer is different.

    From documentation on System.Timers.Timer:
    The server-based Timer is designed for use with worker threads in a multithreaded environment.

    From documentation on System.Windows.Forms.Timer
    Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.

    There is also a System.Threading.Timer, which is safe for multithreaded operations.

    If you are referring to whether to drag a control to the designer or declare it in code, it just depends on your preference. If you dont want to have to keep declaring a new timer and just want to use the same one, then use the control. If you wish to declare it in code, then its up to you. It doesn't really matter which.

    When I am only using one timer, then I generally use the control. If I am having to declare multiple timers, then I generally just declare them in code...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Timers

    Note that in 2003 the System.Windows.Forms.Timer and the System.Timers.Timer were both available from the toolbox, although from different tabs. In 2005 only the System.Windows.Forms.Timer is available by default, but you can add the other manually if you want. As Gig says, they are different and designed for different situations. There's a link that has been posted several times that compares the three types of Timer and you should read it and make your decision based on what you need in each individual situation.

    http://msdn.microsoft.com/msdnmag/is...T/default.aspx

  4. #4

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Timers

    thanks
    Chris

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