|
-
Apr 7th, 2006, 01:36 PM
#1
Thread Starter
Frenzied Member
Timers
Do you prefer.....
To create the timer by code...
VB Code:
Private t As New System.Timers.Timer(2000)
Or use the timer control in the form tray?
and do you use
VB Code:
tmrMain.Stop
'or
tmrMain.Enabled = False
-
Apr 7th, 2006, 01:57 PM
#2
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...
-
Apr 7th, 2006, 07:37 PM
#3
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
-
Apr 8th, 2006, 07:17 AM
#4
Thread Starter
Frenzied Member
Re: Timers
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|