Hi Have this timer that updates every 1000
The timer updates to show if connection to the database is open and valid in the status strip.
But, When The application determines the database connection is closed, then it freezes.
Here is My Code:
Private WithEvents timer As New System.Timers.Timer
--------------------------------------------------------
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timer.Interval = 1000
timer.SynchronizingObject = Me
timer.Start()
End Sub
Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer.Elapsed
Using dbconnect
Try
dbconnect.Open()
If dbconnect.State = ConnectionState.Open Then
DatabaseStatus.Text = "Connected To Database"
DatabaseStatus.BackColor = Color.Green
End If
Catch ex As Exception
DatabaseStatus.Text = "Database Connection Lost"
DatabaseStatus.BackColor = Color.Red
End Try
End Using
End Sub
The timer updates to show if connection to the database is open and valid in the status strip.
But, When The application determines the database connection is closed, then it freezes.
Here is My Code:
Private WithEvents timer As New System.Timers.Timer
--------------------------------------------------------
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timer.Interval = 1000
timer.SynchronizingObject = Me
timer.Start()
End Sub
Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer.Elapsed
Using dbconnect
Try
dbconnect.Open()
If dbconnect.State = ConnectionState.Open Then
DatabaseStatus.Text = "Connected To Database"
DatabaseStatus.BackColor = Color.Green
End If
Catch ex As Exception
DatabaseStatus.Text = "Database Connection Lost"
DatabaseStatus.BackColor = Color.Red
End Try
End Using
End Sub