0

我只是看不到我在这里做错了什么,因为我已经在我的后台工作人员中实现了一个进度条,它不再只运行一次(在某些情况下,我已经看到 foror 循环中的编码运行了 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)

我真的很感激任何帮助,因为我只是不明白为什么我在循环中的编码不应该只运行一次。

4

1 回答 1

2

调用 aFor - 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
于 2012-06-11T16:32:24.303 回答