我的代码有效,但我怀疑我做了什么,因为我将 CheckForIllegalCrossThreadCalls 设置为 false,我认为这会给我的后台工作人员带来一些副作用。这是我的示例代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub go_Click(sender As Object, e As EventArgs) Handles go.Click
Try
If BackgroundWorker1.IsBusy <> True Then
BackgroundWorker1.RunWorkerAsync()
resetevent.Set()
End If
Catch ex As Exception
End Try
End Sub
Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Do
Label1.Text = x
Label2.Text = Label1.Text
Label3.Text = Label2.Tex
Label4.Text = Label3.Text
Label5.Text = Label4.Text
x+=1
Loop While (x < 100)
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As System.Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Try
Catch ex As Exception
End Try
End Sub
Private Sub BackgroundWorker1_Completed(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Try
Catch ex As Exception
End Try
End Sub
有没有办法让我在不将 CheckForIllegalCrossThreadCalls 设置为 False 的情况下为后台工作人员中的标签设置值?因为我的程序遇到了一些错误,即使尚未达到计数器限制,循环也会突然停止。