Link to home
Create AccountLog in
Avatar of fernandovitale
fernandovitaleFlag for Argentina

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
        BackgroundWorker1.WorkerReportsProgress = True
    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        While True
            BackgroundWorker1.ReportProgress(-1, SW.Elapsed.Minutes.ToString("00") & ":" & SW.Elapsed.Seconds.ToString("00"))
        End While
    End Sub

    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        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
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
remove this line:


Open in new window

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.