The problem is that you are calling .BeginInvoke() in your RefreshReport() method. The BackgroundWorker.DoWork() method is already created in another thread, so you can just call rvReport.RefreshReport() . It should look like this:
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork rvReport.RefreshReport() End Sub
It really is that simple, with the possible addition of using Monitor to lock your report object and prevent re-entry.
Right now, when you call .BeginInvoke() , the report process starts, but it does not block at all, so there is nothing left for the DoWork() method. He returns immediately. At this point, BackgroundWorker thinks it's done, so it calls the .RunWorkerCompleted() method, which stops your progress bar.
Based on the comment, rvReport is a visual control, not a component or a simple data access class. In this case, you should be aware that the visual controls in .Net are not thread safe and therefore should never directly do anything directly that takes more than a few minutes. The hoops you passed with .BeginInvoke() in the .BeginInvoke() method had the effect of calling your long-term function in the main user interface thread.
To solve this problem, you need to either disable cross-thread checking so that an exception is not thrown (simple, but not recommended), or your use of the control has changed, so that the main work will happen elsewhere, and the control simply raises events when everything is ready. If you cannot change the control to such an extent, this is a design flaw in the control.
source share