I have an application that has to run a test on a piece off eqipment based on 12 time intervals stored in a database. I have the app working but it seems like there must be a better way to do it. Below is a simplified version of what I have now. I would like to have one event handler handle all the timers but the problem is I need to know which timer called the event so I can updated the correct row in the database. Any suggestion would be appreciated.
Code:
Public Class frmMain
Dim con As New SqlConnection(My.Settings.conString)
Dim WithEvents timer1 As New System.Timers.Timer
Dim WithEvents timer2 As New System.Timers.Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim intervalsCommand As New SqlCommand("SELECT * FROM reponse_intervals ORDER BY minutes", con)
Dim intervals As SqlClient.SqlDataReader
Dim loopCounter As Int16 = 1
Using con
con.Open()
intervals = intervalsCommand.ExecuteReader
Do While intervals.Read
If intervals.Item(0) <> "0" Then
timers(loopCounter).Interval = intervals.Item(0)
End If
Loop
End Using
End Sub
Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
timer1.start
timer2.start
End Sub
Private Sub test(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer1.Elapsed
UpdateDBRow(1, ReadSensor)
End Sub
Private Sub test(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer1.Elapsed
UpdateDBRow(2, ReadSensor)
End Sub
End Class