BackgroundWorker.WorkerReportsProgress Fails

In trying to use the BackgroundWorker I have been unable to get it to report progress. The WorkerReportsProgress property is set to True but that does not seem to work. The thread is a subroutine in a separate module that is accessed from several locations so I don't want to copy it over for each location. The background thread works fine without progress reporting.  The code snippet shows what I think are the relevant items.
Code in calling form:
 
		'preliminary stuff of no interest
            BackgroundWorker2.WorkerSupportsCancellation = True
            BackgroundWorker2.RunWorkerAsync()
				Catch ex as exception
						'exception handling
				End Try
		End Sub
    Private Sub BackgroundWorker2_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
        BackgroundWorker2.WorkerReportsProgress = True
        StratBuild()
 
    End Sub
 
 
Code in background thread:
 
					'preliminary stuff of no interest
 
            If IsFormLoaded("frmReadInvoiceFile") And AuditInfo.FileType > 4 Then
                If rs3.RecordCount > 0 Then
                     frmReadInvoiceFile.BackgroundWorker2.ReportProgress(Math.Min(100, 100 * RecNbr / rs3.RecordCount))
                End If
            End If
            
           'more stuff of no interest

Open in new window

LVL 1
rkulpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I can't see how "RecNbr" is incremented.

Bob
0
J1H1W1Commented:
You need to set the BackgroundWorker.ReportsProgess property before you call RunWorkerAsync.  Then subscribe to the ProgressChanged event.
0
Éric MoreauSenior .Net ConsultantCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

rkulpAuthor Commented:
Bob,

RecNbr is incremented in prior code. I don't think it has a bearing on this error.

J1H1W1,

In the original way I had the code, BackgroundWorker1.WorkerReportsProgress = True was before the call to RunWorkerAsync().

Eric,

I'll look at it. Thanks for the link.
0
rkulpAuthor Commented:
Eric,
None of my references used the code:
Dim worker as BackgroundWorker = CType(sender,BackgroundWorker).
The code I had required the New sub to initialize the form which was referenced and that caused the problem.  Thanks very much.
0
rkulpAuthor Commented:
Eric's example provided the clue. Putting the BackgroundWorker and DoWorkEventArgs in as parameters to the subroutine and then referencing them in the subroutine solved the problem. The real problem was in the full reference:  
frmReadInvoiceFile.BackgroundWorker2.ReportProgress(Math.Min(100, 100 * RecNbr / rs3.RecordCount))
This required the form to be initialized again and the BackgroundWorker properties were lost. His example provided a complete solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.