473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using Background worker

54
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 so that every 5 seconds it will check for the condition? Thanks

Expand|Select|Wrap|Line Numbers
  1. Private Sub TimerIterate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerIterate.Tick
  2.         Call IterateMovement()
  3.     End Sub
  4.  
  5.  
  6. Public Sub IterateMovement()
  7.         Dim SQLCon As SqlConnection
  8.         Dim dtDays As New DataSet
  9.         strUsername = GetSetting("Lands", "Connection", "DataL1")
  10.         strPassword = GetSetting("Lands", "Connection", "DataL2")
  11.         strServerName = GetSetting("Lands", "Connection", "DataL3")
  12.         strInitialCatalog = GetSetting("Lands", "Connection", "DataL4")
  13.         DataL1 = strUsername & strPassword & " Connect Timeout=0; " & strServerName & strInitialCatalog
  14.         SQLCon = New SqlConnection
  15.         daAdapter = New SqlDataAdapter
  16.         dtDays = New DataSet
  17.         SQLCon.ConnectionString = DataL1
  18.         'Weekly Files to be received
  19.         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"
  20.         daAdapter.SelectCommand = New SqlCommand(Query, SQLCon)
  21.         Try
  22.             SQLCon.Open()
  23.             daAdapter.Fill(dtDays, "File_movement").ToString.Trim()
  24.             Dim table As DataTable = dtDays.Tables("File_movement")
  25.             If table.Rows.Count > 0 Then
  26.                 frmHome.ToolTip1.Show("YOU HAVE FILE(S) TO RECEIVE, CLICK ON THE BUTTON TO SEE THEM", frmHome.btnMessage, 10000)
  27.                 frmHome.ToolTip1.ToolTipTitle = "Lands Messenger"
  28.                 frmHome.ToolTip1.UseAnimation = True
  29.                 frmHome.btnMessage.Visible = True
  30.                 frmHome.ToolTip1.BackColor = Color.Red
  31.                 frmHome.ToolTip1.ForeColor = Color.White
  32.             Else
  33.                 frmHome.ToolTip1.Hide(frmHome.btnMessage)
  34.                 frmHome.btnMessage.Visible = False
  35.             End If    
  36.             daAdapter.Dispose()
  37.             dtDays.Dispose()
  38.             SQLCon.Dispose()
  39.             daAdapter = Nothing
  40.             SQLCon.Close()
  41.             SQLCon = Nothing
  42.         Catch
  43.  
  44.         End Try
  45.     End Sub
  46. #End Region
  47.  
Jan 29 '14 #1
1 1306
Luk3r
300 256MB
I found this website very useful when learning about BackgroundWorkers. http://www.vbforums.com/showthread.p...rker-Component
Jan 29 '14 #2

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

Similar topics

7
by: bryanjhogan | last post by:
Hi all, I have a GUI application that uses timers -------------------- TimerCallback readDelegate; TimerCallback deleteDelegate; private Timer readTimer; private Timer deleteTimer;
1
by: bilosta | last post by:
I need help with background worker and form I have a class (form1) that works with database. I need this: -Show form2 while form1 is geting data from database -When form1 is done, close form2,...
6
by: sjoshi | last post by:
I'm able to use the Bacground Worker class to execute task and pain the UI. However I want to be able to execute n tasks in order, say n1, then n2 if there were no errors during n1, n3 so on. ...
4
by: Jesse Aufiero | last post by:
I'm wondering what the rule is on how to assure that the background worker 'DoWork' routine is truly running entirely in the background. My DoWork routine calls another procedure which resides in...
4
by: csharpula csharp | last post by:
Hello, Can you please tell me if I should use the background worker in the following way: if (worker.IsBusy) worker.CancelAsync(); (or I can avoid this if)? And in case I want to restart the...
7
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do...
2
by: thoffman | last post by:
Hello again everyone! I have an issue that I can't seem to find a straight answer for anywhere... I have a For loop that sends a file name to a background worker that contains some long running...
1
by: Infog | last post by:
I am trying to code a simple background workers class without needing to use the backgroundworker object on a form. This would allow me to use a background worker in any class without writing much...
0
by: malique84 | last post by:
I am having troubles with a background worker that will have processes running. If the last process started on the background worker completes it calls the RunWorkCompleted method, even if all of...
1
Pakmarshal
by: Pakmarshal | last post by:
Hi, I m developing an application in vb 2008, and using background worker to copy file(s). I have my own designed form which plays an animationon on the top of the form along with copy. For...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.