vb.net类backgroundworker报告进度

vb.net类backgroundworker报告进度,vb.net,class,progress-bar,backgroundworker,Vb.net,Class,Progress Bar,Backgroundworker,由于清理了我的代码,a试图从backgroundworker调用的另一个类更新progressbar。 我怎样才能实现这个目标 我试过: Public Class Form1 'backgroundworker and progressbar are located in Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load BackgroundWor

由于清理了我的代码,a试图从backgroundworker调用的另一个类更新progressbar。 我怎样才能实现这个目标

我试过:

    Public Class Form1
    'backgroundworker and progressbar are located in Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        BackgroundWorker1.WorkerReportsProgress = True
        BackgroundWorker1.WorkerSupportsCancellation = True
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        BackgroundWorker1.RunWorkerAsync()
        End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim asyncwork As New calc
        asyncwork.calculate()
    End Sub

    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
    End Sub
End Class
Public Class calc
    Public Sub calculate()
        Form1.BackgroundWorker1.ReportProgress(100)
    End Sub
End Class
以前,当所有任务都在同一个类中完成时,我的代码正常工作:

 Public Class Form1
    'backgroundworker and progressbar are located in Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        BackgroundWorker1.WorkerReportsProgress = True
        BackgroundWorker1.WorkerSupportsCancellation = True
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    calclocal()
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        calclocal()
    End Sub

    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
    End Sub
    Sub calclocal()
        BackgroundWorker1.ReportProgress(100)
    End Sub

End Class
有人有主意吗


谢谢

抱歉可能重复,但您的示例没有使用单独的类来报告进度。请看一下第一个代码。这必须通过不同的方式来解决。表单是类(在每个表单的顶部都有这样的说明:
公共类FormX
),因此链接特别相关。在一个窗体实例中执行工作并在另一个窗体实例中报告它与在自定义类中执行工作并向窗体报告没有什么不同。您使用的是隐式表单实例,这没有任何帮助。那么,如何从其他类报告并使用backgroundworker?类似于:或者有人知道如何在vb.net中解决此问题吗?