[RESOLVED] VB 2010: Cross-thread problem with Progress Bar
Alright so I finished my first program and I'm working on my second. I copied over a bunch of stuff and now the only problem I am having is this error with my progress bar.
"Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on."
I've fixed this before, but I can't quite remember. Here is the code it is being used by-
Code:
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = Convert.ToInt32(100 * P / 2)
End Sub
Re: VB 2010: Cross-thread problem with Progress Bar
Invoke the UI thread to access the progressbar properties.
vb Code:
ProgressBar1.Invoke(Sub() ProgressBar1.Value = Convert.ToInt32(100 * P / 2))
Re: VB 2010: Cross-thread problem with Progress Bar
Thanks! Although, I found the problem once I read back through my code. The report progress was set to the wrong progress change.
Re: [RESOLVED] VB 2010: Cross-thread problem with Progress Bar
The cross thread issue has more to do with threads trying to take action on threads that aren't their own.
Re: [RESOLVED] VB 2010: Cross-thread problem with Progress Bar
That really did help though, on a totally different part of my program xD Thanks.
Re: [RESOLVED] VB 2010: Cross-thread problem with Progress Bar
No problem, as long as you've got things figured out :)