我正在使用多个线程来执行某些进程,并且我想在进度条中显示总进度,那么如何以安全的方式执行 ProgressBar1.Increment(1)?
Public Sub thread1process()
For i = 0 To t1.Rows.Count - 1
t1.Rows(i)("cname") = "Thread1"
t1.Rows(i)("PD") = i
t1.Rows(i)("PDP") = i
t1.Rows(i)("TPD") = i
t1.Rows(i)("TPDP") = i
ProgressBar1.Increment(1)
Next
End Sub
Public Sub thread2process()
For i = 0 To t2.Rows.Count - 1
t2.Rows(i)("cname") = "Thread2"
t2.Rows(i)("PD") = i
t2.Rows(i)("PDP") = i
t2.Rows(i)("TPD") = i
t2.Rows(i)("TPDP") = i
ProgressBar1.Increment(1)
Next
End Sub
另外我将如何同时从多个线程中增加一个公共变量?