Avatar of fernandovitale
Flag 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
Visual Basic.NET

Avatar of undefined
Last Comment
Jacques Bourgeois (James Burger)

8/22/2022 - Mon
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

remove this line:


Open in new window

Jacques Bourgeois (James Burger)

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.
Your help has saved me hundreds of hours of internet surfing.