fernandovitale
asked on
backgroundworker VB.NET
I have this code:
Public Class Form1
Private SW As New Stopwatch
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
SW.Start()
BackgroundWorker1.WorkerRe portsProgr ess = True
BackgroundWorker1.RunWorke rAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(B yVal sender As System.Object, ByVal e As System.ComponentModel.DoWo rkEventArg s) Handles BackgroundWorker1.DoWork
While True
BackgroundWorker1.ReportPr ogress(-1, SW.Elapsed.Minutes.ToStrin g("00") & ":" & SW.Elapsed.Seconds.ToStrin g("00"))
System.Threading.Thread.Sl eep(1000)
End While
End Sub
Private Sub BackgroundWorker1_Progress Changed(By Val sender As Object, ByVal e As System.ComponentModel.Prog ressChange dEventArgs ) Handles BackgroundWorker1.Progress Changed
Label1.Text = e.UserState.ToString
End Sub
End Class
The BackgroundWorker starts when my application executes a SQL query, But the clock remains frozen until the query ends ... want the timer to continue running while the query is executed, how can i do this?
thank you very much
Public Class Form1
Private SW As New Stopwatch
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
SW.Start()
BackgroundWorker1.WorkerRe
BackgroundWorker1.RunWorke
End Sub
Private Sub BackgroundWorker1_DoWork(B
While True
BackgroundWorker1.ReportPr
System.Threading.Thread.Sl
End While
End Sub
Private Sub BackgroundWorker1_Progress
Label1.Text = e.UserState.ToString
End Sub
End Class
The BackgroundWorker starts when my application executes a SQL query, But the clock remains frozen until the query ends ... want the timer to continue running while the query is executed, how can i do this?
thank you very much
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you on SQL Server? Are you using the SqlClient namespace? If so, how to do execute the query?
Since your problem involves a query, you should show us the code that runs the query, because the solution could be there.
For instance, if you could answer yes to the first 2 questions and are not using one of those tools that are suppose to help but usually prevents you from controlling what is happening (LINQ, Data Entities and a few others) there might be ways to call the query in an asynchrone mode that will let the application run in paraller with the query without having to deal with threads or the background worker.
Since your problem involves a query, you should show us the code that runs the query, because the solution could be there.
For instance, if you could answer yes to the first 2 questions and are not using one of those tools that are suppose to help but usually prevents you from controlling what is happening (LINQ, Data Entities and a few others) there might be ways to call the query in an asynchrone mode that will let the application run in paraller with the query without having to deal with threads or the background worker.
Open in new window