I am using vb.net 2008 which is connected to sql 2008. I have a timer control and a tooltip. The timer always keeps on ticking and when a condition is met the tooltip displays a message. My problem now is the timer hangs or freezes the program.
I thought of a Background worker that works on a separate thread, but how to go about it.
How can I put the IterateMovement procedure below in a background worker? Thanks
Private Sub TimerIterate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerIterate.Tick
Call IterateMovement()
End Sub
Public Sub IterateMovement()
Dim SQLCon As SqlConnection
Dim dtDays As New DataSet
strUsername = GetSetting("Lands", "Connection", "DataL1")
strPassword = GetSetting("Lands", "Connection", "DataL2")
strServerName = GetSetting("Lands", "Connection", "DataL3")
strInitialCatalog = GetSetting("Lands", "Connection", "DataL4")
DataL1 = strUsername & strPassword & " Connect Timeout=0; " & strServerName & strInitialCatalog
SQLCon = New SqlConnection
daAdapter = New SqlDataAdapter
dtDays = New DataSet
SQLCon.ConnectionString = DataL1
'Weekly Files to be received
Dim Query As String = "Select * from File_Movement where Movement_to ='" & frmVisibleNot.txtUsername.Text.Trim & "' and Received_By is null and fdate > dateadd(day,-7, getdate()) order by Fdate desc,Ftime desc"
daAdapter.SelectCommand = New SqlCommand(Query, SQLCon)
Try
SQLCon.Open()
daAdapter.Fill(dtDays, "File_movement").ToString.Trim()
Dim table As DataTable = dtDays.Tables("File_movement")
If table.Rows.Count > 0 Then
frmHome.ToolTip1.Show("YOU HAVE FILE(S) TO RECEIVE, CLICK ON THE BUTTON TO SEE THEM", frmHome.btnMessage, 10000)
frmHome.ToolTip1.ToolTipTitle = "Lands Messenger"
frmHome.ToolTip1.UseAnimation = True
frmHome.btnMessage.Visible = True
frmHome.ToolTip1.BackColor = Color.Red
frmHome.ToolTip1.ForeColor = Color.White
Else
frmHome.ToolTip1.Hide(frmHome.btnMessage)
frmHome.btnMessage.Visible = False
End If
daAdapter.Dispose()
dtDays.Dispose()
SQLCon.Dispose()
daAdapter = Nothing
SQLCon.Close()
SQLCon = Nothing
Catch
End Try
End Sub
#End Region