I would like to use a background worker to update the end user for a long running process. Unfortunately I have updates to datagridviews on long running processes so I keep getting the cross thread errors. Is there a way to avoid this with a background worker and how does one do it? Here is some code snippets but if I use the backgroundworker in this manner it doesn't update the textbox until after the long running process is finished which is obviously useless in the way I am trying to do it. Any help would be appreciated. Thanks!
Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork BackgroundWorker1.ReportProgress(5, "Running some long process...") End Sub Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged Label5.Text = CType(e.UserState, String) & " " & e.ProgressPercentage.ToString End Sub
I need a better way to update the UI. I would eventually like to use a progress bar but unfortunately everywhere on the internet has the long running process just running some loop with a cheap example that doesn't actually help anyone that has UI calls on the long running process. For instance, I am loading gridviews and textboxes on a separate form and would like to update the end user such that each time a new gridview is filled to say "... gridview1 is filled..." "gridview2 is filled..." etc. Thanks!