I have a progressbar on my form that is not getting开发者_如何学C updated.
When the Send Email button is clicked I do this:
Public Sub SendMail()
If CheckSettings() = False Then Exit Sub
BackUpEbillFile()
LockForm(True)
StatusBars(1, "Sending emails...")
ProgressBar1.Maximum = intInvoicesToSend
BackgroundWorker1.RunWorkerAsync()
End Sub
I have the following events:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
e.Result = SendBills()
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Console.WriteLine("I DID IT MA!!!!1 status: " & ProgressBar1.Value)
ProgressBar1.PerformStep()
Console.WriteLine("I DID IT MA!!!!2 status: " & ProgressBar1.Value)
End Sub
In the SendBills, which is in a mail class, I do this:
smtp.Send(msg)
Console.WriteLine("I DID IT PA!!!! count: " & iCount)
frmBilling.BackgroundWorker1.ReportProgress(iCount)
My problem lies at the ProgressBar1.PerformStep() in the ProgressChanged. I am getting to the progress changed but the Progressbar1 is not changing. It stays at zero.
- intInvoicesToSend is 16
- ProgressBar1.Minimum = 0
- ProgressBar1.Maximum = intInvoicesToSend (which was 16)
- ProgressBar1.Step = 1
Here is my console from the console.writelines:
I DID IT PA!!!! count: 0
I DID IT MA!!!!1 status: 0
I DID IT MA!!!!2 status: 1
I DID IT PA!!!! count: 1
I DID IT MA!!!!1 status: 1
I DID IT MA!!!!2 status: 2
I DID IT PA!!!! count: 2
I DID IT MA!!!!1 status: 2
I DID IT MA!!!!2 status: 3
I DID IT PA!!!! count: 3
I DID IT MA!!!!1 status: 3
I DID IT MA!!!!2 status: 4
Can anyone tell me what I'm doing wrong? Thanks!
My suspicion is that you're calling the ReportProgress
method on the wrong instance.
See this line:
frmBilling.BackgroundWorker1.ReportProgress(iCount)
If the BackgroundWorker is defined directly within your form, you can leave off the frmBilling
portion, and just specify this as:
BackgroundWorker1.ReportProgress(iCount)
The way you have it may be causing the ReportProgress
to get called on the wrong instance...
try this...
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Console.WriteLine("I DID IT MA!!!!1 status: " & ProgressBar1.Value)
ProgressBar1.PerformStep()
Application.DoEvents()
Console.WriteLine("I DID IT MA!!!!2 status: " & ProgressBar1.Value)
End Sub
精彩评论