Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is when you call <code>.BeginInvoke()</code> in your <code>RefreshReport()</code> method. The <code>BackgroundWorker.DoWork()</code> method is already raised in a different thread, so you can just call <code>rvReport.RefreshReport()</code>. It should look like this:</p> <pre><code>Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork rvReport.RefreshReport() End Sub </code></pre> <p>It really is that simple, with the possible addition of using a <code>Monitor</code> to lock your report object and prevent re-entry.</p> <p>Right now, when you call <code>.BeginInvoke()</code> the report process kicks off, but it doesn't block at all so there's nothing left for the <code>DoWork()</code> method to do. It just returns right away. At this point the BackgroundWorker thinks it's done, so calls the <code>.RunWorkerCompleted()</code> method, which stops your progress bar.</p> <hr> <p>Based on the comment, <code>rvReport</code> is a visual control rather than a component or simple data access class. In that case, you should know that visual controls in .Net are not thread safe, and therefore should <em>never</em> directly do anything directly that takes more than a few moments to complete. The hoops you were jumping through with <code>.BeginInvoke()</code> in the <code>RefreshReport()</code> method had the effect of calling your long running function <em>in the main UI thread</em>. </p> <p>To solve this problem, you need to either turn off cross thread checking so that the exception is not thrown (simple, but not recommended) or change how you use the control, so that the main work happens elsewhere and the control just raises events when things are ready. If you can't modify the control to that extent, it's a design flaw in the control.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload