By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Timer Control / Threading

P: 54
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
Expand|Select|Wrap|Line Numbers
  1. ' The sub procedure 'AllocationExpiryDate' is called to the Tick event of the timer control. 
  2. Public Sub AllocationExpiryDate()
  3.         Dim SQLCon As New SqlConnection : Dim dtTable As New DataSet
  4.         strUsername = GetSetting("Allocation", "Connection", "DataL1")
  5.         strPassword = GetSetting("Allocation", "Connection", "DataL2")
  6.         strServerName = GetSetting("Allocation", "Connection", "DataL3")
  7.         strInitialCatalog = GetSetting("Allocation", "Connection", "DataL4")
  8.         DataL1 = strUsername & strPassword & strServerName & strInitialCatalog
  9.         SQLCon.ConnectionString = DataL1
  10.         Try
  11.             SQLCon.Open()
  12.             Dim Query As String = "Select * from Alloc order by Allocation_Due_Date asc"
  13.             daAdapter = New SqlDataAdapter(Query, SQLCon)
  14.             daAdapter.Fill(dtTable, "Alloc")
  15.             Dim table As DataTable = dtTable.Tables("Alloc")
  16.             If table.Rows.Count > 0 Then
  17.                 Dim ctr As Integer
  18.                 For ctr = 0 To table.Rows.Count - 1
  19.                     Dim dtAllocExpDate = FormatDateTime(table.Rows(ctr).Item("Allocation_Due_Date").ToString.Trim, DateFormat.ShortDate)
  20.                     If dtAllocExpDate = Now Then Then
  21.                         frmMainForm.ToolTip1.Show("Allocation note is due for revision. Refer to the allocation list", frmMainForm.btnExpiry)
  22.                     End If
  23.                 Next
  24.             End If
  25.         Catch ex As Exception
  26.             MsgBox(Err.Description)
  27.         End Try   
  28.     End Sub
Jun 28 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,731
Have you considered using a Thread?
The BackgroundWorker class is pretty useful for this type of thing. Check out this MSDN article about How to use the BackgroundWorker.

Jul 2 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.