我只是看不出我在这里做错了什么,因为我已经在后台工作器中实现了一个进度条,它不再只运行一次(在某些情况下,我已经看到在foor循环中编码运行6次)
我的编码: -
My progress bar max value is set to 10.
‘ BGWorker Do Work Event
For i As Integer = 1 To 2
‘ Run code 1
Next
For i As Integer = 2 To 3
‘ Run code 2
Next
For i As Integer = 3 To 4
‘ Run code 3
Next
For i As Integer = 4 To 5
‘ Run code 4
Next
For i As Integer = 5 To 6
‘ Run code 5
Next
For i As Integer = 6 To 8
‘ Run code 6
Next
For i As Integer = 8 To 9
‘ Run code 7
Next
‘ BGWorker Progress changed event
Me.Progressbar1.Value = e.ProgressPercentage
Me.label1.Text = String.Format("{0} % Completed", e.ProgressPercentage * 10)
我真的很感激任何帮助,因为我不知道为什么我在循环中的编码不应该只运行一次。
答案 0 :(得分:2)
调用For - Loop 1 to 2
将运行两次。 3 to 4
,5 to 6
也是如此。
您的原始代码只是:
For i As Integer = 1 To 2
‘ Run code 1
Next
For i As Integer = 3 To 4
‘ Run code 2
Next
做了同样的事情。
但听起来你根本不需要For - Loops
,如果你所做的只是运行一次代码。如果您的后台工作人员有十个步骤,请尝试调用十个更新:
‘ Run code 1
BGWorker.ReportProgress(1)
‘ Run code 2
BGWorker.ReportProgress(2)
‘ Run code 3
BGWorker.ReportProgress(3)
‘ etc