Saturday, 31 August 2013

Timer not starting in vb.net

Timer not starting in vb.net

net program that uses excel as a datasource. I then fill a datagridview
with this datasource and make changes to the dataset via the datagridview.
I'm trying to find a way to refresh this dataset via a button that will
update the values after a change. My only problem is that I'm trying to
set up a timer in my refresh method but it never initializes/starts. I
can't figure out why, from what I've found online the way to start a timer
in vb.net is to set the timer variable to enabled = true. I've stepped
into my debugger and found that the timer never starts. Here is my code
below, if there is anyone who can figure out why this timer isn't starting
I would greatly appreciate your help!
Dim mytimer As New System.Timers.Timer
Sub refresh()
write2Size()
mytimer.timer = New System.Timers.Timer(20000)
'Starting Timer
mytimer.Enabled = True
Cursor.Current = Cursors.WaitCursor
AddHandler mytimer.Elapsed, AddressOf OnTimedEvent
'Setting the cursor back to normal here
Cursor.Current = Cursors.Default
mytimer.Enabled = False
objworkbook.Save()
objExcel.ActiveWorkbook.Save()
myDS.Clear()
retrieveUpdate()
End Sub
Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
Console.WriteLine("The Elapsed event was raised at {0}, e.SignalTime)
End Sub

No comments:

Post a Comment