i am using multiple threads to do some processes and i want to display the total progress in a progressbar so How can i do the ProgressBar1.Increment(1) in a safe way?
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
also how would i increase a public variable from multiple threads in the same time?
You could use the
Invokemethod on the Form in order to marshal the call on the main UI thread.Use the
Interlocked.Incrementmethod.