当我使用以下代码时,我正在获取应用程序正在使用的进度条的值:
Dim progressBarThread = New Thread(New ThreadStart(AddressOf Me.ThreadProcSafe))
Me.Invoke(New MethodInvoker(AddressOf progressBarThread.Start))
Do
status = range.Current.Value.ToString
numwaits += 1
'Me.Invoke(New MethodInvoker(AddressOf progressBarThread.Start))
Wait(5)
Loop While status <> 100 AndAlso numwaits < 50
LogMessage("100%" + Environment.NewLine)
Delegate Sub SetTextCallback([text] As String)
Private Sub ThreadProcSafe()
Me.SetText(status)
End Sub
Private Sub SetText(ByVal [text] As String)
If Me.TextBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.ProgressBar1.Value = [text]
End If
End Sub
问题在于它只获得值一次,并且不会像我想要的那样不断更新值。正如您在上面的代码中看到的那样,我尝试在循环中使用 Me.Invoke(New MethodInvoker(AddressOf progressBarThread.Start)),以查看它是否会以这种方式更新值,但它确实如此不起作用并导致错误。
我该如何做到这一点?