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
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