0
我有2個進度條。現在我在代碼中做了一些其他的事情,這需要時間來執行,因此需要使用backgroundworker
。我沒有太多的想法如何使用backgroundworker
。我這裏沒有包含的其他代碼執行得很好,但progressbar
的值不會改變,也不會改變它們的文本。我將如何實現這一目標?VB.NET從BackgroundWorker更改進度條值?
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
是的,這樣做的工作,比我想象的要簡單得多:)謝謝 – Legjendat 2013-02-26 03:07:03