S
Steve K.
I understand the concepts and rules for invoking UI methods from a non-UI
thread. In the past I have always checked with the control's InvokeRequired
property and Invoked my delegate accordingly. This has worked fine, nothing
special.
BUT, I am now working on my first client/server app and I have a slightly
new challenge that I'm not finding a good solution for.
My client passes an EventShim with a callback to the server. When something
special happens on the server it fires this event which the client of course
responds to.
The event handler on the client is taking args from the server-fired event
and adding items to a DataBound collection. I designed it this way on
purpose, I didn't want to tear down and build up the UI controls every time
a couple new items came over, data binding seemed a perfect fit.
Problem is that when the items are added to the collection and they raise
the INotifyChange event (I think that's the one) I'm getting cross-thread
exceptions. Not surprising. Now, since I'm not directly making calls to a
"UI" object my old habits of InvokeRequire/BeginInvoke on the control won't
work.
My question: How do I invoke a delegate on the UI thread without having
acccess to a System.Windows.Forms.Control object? How else can we execute
on the UI thread?
Thanks for any help, I'm close to getting this deliverable wrapped up and
going to sleep (just in time for breakfast!) :0)
-Steve
thread. In the past I have always checked with the control's InvokeRequired
property and Invoked my delegate accordingly. This has worked fine, nothing
special.
BUT, I am now working on my first client/server app and I have a slightly
new challenge that I'm not finding a good solution for.
My client passes an EventShim with a callback to the server. When something
special happens on the server it fires this event which the client of course
responds to.
The event handler on the client is taking args from the server-fired event
and adding items to a DataBound collection. I designed it this way on
purpose, I didn't want to tear down and build up the UI controls every time
a couple new items came over, data binding seemed a perfect fit.
Problem is that when the items are added to the collection and they raise
the INotifyChange event (I think that's the one) I'm getting cross-thread
exceptions. Not surprising. Now, since I'm not directly making calls to a
"UI" object my old habits of InvokeRequire/BeginInvoke on the control won't
work.
My question: How do I invoke a delegate on the UI thread without having
acccess to a System.Windows.Forms.Control object? How else can we execute
on the UI thread?
Thanks for any help, I'm close to getting this deliverable wrapped up and
going to sleep (just in time for breakfast!) :0)
-Steve