Timer Control / Threading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Benniit
    New Member
    • May 2008
    • 54

    Timer Control / Threading

    The code below loops through all the records and checks if Allocation_Due_ Date is equal to the current date. If a match is found, the tooltip displays it on a button on the form. My problem is a time will come and the records will be many which will cause the machine to hang. So if someone can help me place the below code in a thread to free the machine from hanging. Thank you
    Code:
    ' The sub procedure 'AllocationExpiryDate' is called to the Tick event of the timer control. 
    Public Sub AllocationExpiryDate()
            Dim SQLCon As New SqlConnection : Dim dtTable As New DataSet
            strUsername = GetSetting("Allocation", "Connection", "DataL1")
            strPassword = GetSetting("Allocation", "Connection", "DataL2")
            strServerName = GetSetting("Allocation", "Connection", "DataL3")
            strInitialCatalog = GetSetting("Allocation", "Connection", "DataL4")
            DataL1 = strUsername & strPassword & strServerName & strInitialCatalog
            SQLCon.ConnectionString = DataL1
            Try
                SQLCon.Open()
                Dim Query As String = "Select * from Alloc order by Allocation_Due_Date asc"
                daAdapter = New SqlDataAdapter(Query, SQLCon)
                daAdapter.Fill(dtTable, "Alloc")
                Dim table As DataTable = dtTable.Tables("Alloc")
                If table.Rows.Count > 0 Then
                    Dim ctr As Integer
                    For ctr = 0 To table.Rows.Count - 1
                        Dim dtAllocExpDate = FormatDateTime(table.Rows(ctr).Item("Allocation_Due_Date").ToString.Trim, DateFormat.ShortDate)
                        If dtAllocExpDate = Now Then Then
                            frmMainForm.ToolTip1.Show("Allocation note is due for revision. Refer to the allocation list", frmMainForm.btnExpiry)
                        End If
                    Next
                End If
            Catch ex As Exception
                MsgBox(Err.Description)
            End Try   
        End Sub
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Have you considered using a Thread?
    The BackgroundWorke r class is pretty useful for this type of thing. Check out this MSDN article about How to use the BackgroundWorke r.

    -Frinny

    Comment

    Working...