Waldo2k2
Member
- Joined
- Feb 6, 2006
- Messages
- 7
- Programming Experience
- 5-10
I'm having some trouble with invoking and delegates. The basic problem is, I just upgraded a project to VS 2005, and now I come to find I was doing some things illegally in my code. I've been calling the progressbar.performstep() method from within a thread that isn't the UI thread. I've looked at every tutorial on delegates and invoking that I can find, but what I've done so far still causes the application to error. Here's the basic idea of what I'm doing
This of course is a run-time error. I can't figure out why it's not invoking onto the UI thread, any ideas?
VB.NET:
'using an integer as an index to what progressbar i want to update
'was just passing the name of the progressbar but wanted to avoid
'any conflicts that may have been causing between threads
Private Delegate Sub pbarDelegate(ByVal index As Integer)
private sub callThread()
theThread.Start()
end sub
private sub insideThread()
'this is what runs when the thread starts
Dim cobarDelegate As pbarDelegate
cobarDelegate = New pbarDelegate(AddressOf dostep)
cobarDelegate.Invoke(1)
end sub
Private Sub dostep(ByVal index As Integer)
Select Case index
Case 1
'error is of course right here
cobar.PerformStep()
Case 2
adbar.PerformStep()
Case 3
embar.PerformStep()
Case 4
prbar.PerformStep()
End Select
End Sub