My application's form is handling an event raised from a worker thread in
another object. In the event handler I want to call a sub procedure that
does a number of things and among those things is accessing controls on
the form. This sub procedure normally has been called from the Click
event procedure of a button on the form so there haven't been any issues
with accessing controls from outside the UI thread. Now I have to
consider this.
I could create delegates for all the procedures I need to Invoke on the
controls but I was hoping there was a simpler way. Is there any way to
force the UI thread to call a sub procedure without using Control.Invoke
()? For example:
Private myObj As MyObject
Private Sub MainForm_Load ...
...
AddHandler myObj.SomeEvent, AddressOf MyObject_SomeEvent
...
End Sub
Private Sub MyObject_SomeEvent(ByVal whatever As Integer)
' SomeEvent is raised by a worker thread in MyObject.
' How can I force the UI thread to call SomeProcedure
' from here so I don't have to litter the SomeProcedure
' Sub with If...Then...Else structures testing
' Control.InvokeRequired() and calling Control.Invoke()
' with various custom Delegates that I have to create?
End Sub
Private Sub SomeProcedure(ByVal whatever As Integer)
... Do Stuff
SomeTextBox.Text = "Gooney Goo Goo"
...
End Sub
Hopefully I'm making sense here. I may be a little confused and not
realize it yet.
Joel Moore