background timer process Q

M

Martin Williams

One more tweak to my survey program. Since all the survey records are
stored in a dataset and updated to the database only when the program
closes, I need some sort of protection against a system crash. So, I'm
trying to have a timer running that updates the database every 10 minutes.
I'm wondering if I did this right...

Module Shared Code
Public DataUpdateTimer as New System.Windows.Forms.Timer
Public Sub Main()
Dim delUpdate as new ThreadStart(AddressOf InitializeTimer)
Dim Update as new Thread(delUpdate)
Update.Start()

Sub InitializeTimer()
AddHandler DataUpdateTimer.Tick, AddressOf UpdateData

With DataUpdateTimer
.Interval = 600000
.Enabled = True
.Start()
End With
End Sub

Sub UpdateData(ByVal myObject as Object, ByVal myEventArgs as
EventArgs)
Dim InsertedRows as System.Data.Dataset =
frmMainform.dsSurveyData2.GetChanges(DataRowState.Added)
If Not InsertedRows Is Nothing Then
frmMainForm.odbdaSurvey.Update(InsertedRows)
End If
frmMainForm.dsSurveyData2.AcceptChanges()
DataUpdateTimer.Enabled = True
End Sub
End Module
 
M

Martin Williams

Actually, I figured it out. Amazing what you can accomplish when you're
irritated...

This is what it ended up looking like:

Module Shared Code
Public DataUpdate Timer as new System.Timers.Timer
Public Sub Main()
dim delUpdate as new ThreadStart(AddressOf InitializeTimer)
dim Update as new Thread(delUpdate)
Update.Start()
End Sub

Public Sub InitializeTimer()
AddHandler DataUpdateTimer.Elapsed, AddressOf OnTimer

With DataUpdateTimer
.Enabled = True
.Interval = 300000
.AutoReset = True
End With
End Sub

Public Sub OnTimer(ByVal source As Object, ByVal e as
ElapsedEventArgs)
frmMainForms.odbdaSurvey.Update(frmMainform.dsSurveyData2)
End Sub
End Module

Although I didn't get any responses, thanks to all those who helped me with
my previous questions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top