我有 2 个进度条。现在我在我的代码中做了一些其他的事情,这需要时间来执行,因此需要使用backgroundworker
. 我不太清楚如何使用backgroundworker
. 我没有在这里包含的其余代码执行得很好,但是progressbar
值没有改变,它们的文本也没有改变。我将如何实现这一目标?
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim LM As RegistryKey = Registry.LocalMachine
Dim LM_SW As RegistryKey = LM.OpenSubKey("Software")
Dim LM_MS As RegistryKey = LM_SW.OpenSubKey("Microsoft")
Dim LM_Win As RegistryKey = LM_MS.OpenSubKey("Windows")
Dim LM_CV As RegistryKey = LM_Win.OpenSubKey("CurrentVersion")
Dim AppPaths As RegistryKey = LM_CV.OpenSubKey("App Paths")
Dim NrOfFiles1 As Integer = AppPaths.SubKeyCount
ProgressBar2.Maximum = NrOfFiles1
ProgressBar1.Maximum = 100
For Each FormatString As String In AppPaths.GetSubKeyNames()
ProgressBar2.Value += 1 / NrOfFiles1
ProgressBar1.Value += 1 * ProgressBar2.Value / 100 / 10
ProgressBar1.Text = ProgressBar1.Value & "%"
ProgressBar2.Text = ProgressBar2.Value & "%"
Next
ProgressBar2.Value = 0
End Sub