Click here to Skip to main content
15,914,016 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionTimer Elapsed Event Pin
elcheah17-Jan-06 22:05
elcheah17-Jan-06 22:05 
AnswerRe: Timer Elapsed Event Pin
Joshua Quick17-Jan-06 22:24
Joshua Quick17-Jan-06 22:24 
GeneralRe: Timer Elapsed Event Pin
elcheah17-Jan-06 23:09
elcheah17-Jan-06 23:09 
GeneralRe: Timer Elapsed Event Pin
Joshua Quick18-Jan-06 7:15
Joshua Quick18-Jan-06 7:15 
GeneralRe: Timer Elapsed Event Pin
elcheah18-Jan-06 14:50
elcheah18-Jan-06 14:50 
GeneralRe: Timer Elapsed Event Pin
Joshua Quick18-Jan-06 15:30
Joshua Quick18-Jan-06 15:30 
GeneralRe: Timer Elapsed Event Pin
elcheah18-Jan-06 15:57
elcheah18-Jan-06 15:57 
GeneralRe: Timer Elapsed Event Pin
Joshua Quick18-Jan-06 16:23
Joshua Quick18-Jan-06 16:23 
Now we're getting somewhere. :->
I see a few possible issues here.

(1)
You need a RemoveHandler for every AddHandler that you have. If you don't call RemoveHandler, then your timer will continue to persist in memory, even after your form has been closed. This is because a reference is still being kept alive by the AddHandler function.
The best place to call RemoveHandler is in your form's Closed event handler.

However, an even easier solution is to use a timer control on your form instead, via the designer. The designer will automatically declare the timer member with the "WithEvents" keyword, which automatically hooks up event handlers for you at compile time. When you select its Tick event from the IDE's drop down box, it'll insert that method postfixed with the "Handles" keyword.

(2)
Watch out when using the System.Timers.Timer class. By default, this timer operates on another thread which can cause race conditions when used on a form. You can avoid this issue by synching the timer to your UI's thread. However, an even easier solution is to use System.Windows.Forms.Timer instead, which is a control that's selectable in the UI designer, under the Form section.

(3)
You shouldn't use Timer.Enabled to block access to the TimerFired() method if you're controlling the timer enable from the Form too. This could put the timer in a bad state. Instead you should use a flag like I stated before, which should work once you fix the above issues.
GeneralRe: Timer Elapsed Event Pin
elcheah18-Jan-06 18:03
elcheah18-Jan-06 18:03 
GeneralRe: Timer Elapsed Event Pin
Joshua Quick18-Jan-06 18:23
Joshua Quick18-Jan-06 18:23 
GeneralRe: Timer Elapsed Event Pin
elcheah18-Jan-06 21:17
elcheah18-Jan-06 21:17 
QuestionCalling C function in VB.net Pin
jpvillemagne17-Jan-06 22:04
jpvillemagne17-Jan-06 22:04 
AnswerRe: Calling C function in VB.net Pin
Guffa18-Jan-06 1:08
Guffa18-Jan-06 1:08 
GeneralRe: Calling C function in VB.net Pin
jpvillemagne26-Jan-06 0:28
jpvillemagne26-Jan-06 0:28 
AnswerRe: Calling C function in VB.net Pin
Guffa27-Jan-06 7:06
Guffa27-Jan-06 7:06 
GeneralRe: Calling C function in VB.net Pin
jpvillemagne1-Feb-06 21:21
jpvillemagne1-Feb-06 21:21 
AnswerRe: Calling C function in VB.net Pin
Guffa1-Feb-06 21:40
Guffa1-Feb-06 21:40 
GeneralRe: Calling C function in VB.net Pin
jpvillemagne1-Feb-06 23:10
jpvillemagne1-Feb-06 23:10 
GeneralRe: Calling C function in VB.net Pin
jpvillemagne1-Feb-06 23:14
jpvillemagne1-Feb-06 23:14 
QuestionUrgently required Pin
Osama12317-Jan-06 21:10
Osama12317-Jan-06 21:10 
AnswerRe: Urgently required Pin
Dave Kreskowiak18-Jan-06 4:13
mveDave Kreskowiak18-Jan-06 4:13 
QuestionHow do I add a custom icon to a WinForms DataGrid header row? Pin
nzmike17-Jan-06 21:09
nzmike17-Jan-06 21:09 
AnswerRe: How do I add a custom icon to a WinForms DataGrid header row? Pin
Dave Kreskowiak18-Jan-06 4:11
mveDave Kreskowiak18-Jan-06 4:11 
GeneralRe: How do I add a custom icon to a WinForms DataGrid header row? Pin
nzmike18-Jan-06 14:50
nzmike18-Jan-06 14:50 
GeneralRe: How do I add a custom icon to a WinForms DataGrid header row? Pin
Dave Kreskowiak18-Jan-06 15:46
mveDave Kreskowiak18-Jan-06 15:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.