M
Martin Maat
Hi,
I have a notification window that uses its own thread to animate itself. It
also fires events to the main UI.
The trouble (getting it thread safe) is not with the events fired, I can
marhall them just fine using (Begin)Invoke. It is with the internal thread
which updates the form itself. The form however was not created by this
animation thread which is only created later, after construction of the
form. It was created by the main UI thread.
In framework 1.1 there was no problem and with framework 2.0 I can just set
Control.CheckForIllegalCrossThreadCalls to false and all is fine again. I
tried to be a good boy though, just to be sure there will be no surprises,
to make it thread-safe.
Marshalling every call to the form's message loop using (Begin)Invoke is
pointless, it defeats the purpose of having a separate animation thread.
Animation got jerky, stalling the main UI thread. So I basically wanted the
form to be created on the animation thread itself.
I may be stupid but it took me a couple of days to come to terms with the
fact that this is impossible. It is like lifting yourself up by your shoe
laces.
Now I was thinking... can I not marshall the control to another thread
instead of marshalling each call to the appropriate thread?
Like a control is created on thread A. Then, when in thread B, I want to
mess with it. Then I want to be able to tell Windows "Hey, this control
which is owned by thread A, please consider it owned by thread B from now
on". And then call its methods from thread B.
This would be so much more convenient in my scenario. Can it be done?
Regards, Martin.
I have a notification window that uses its own thread to animate itself. It
also fires events to the main UI.
The trouble (getting it thread safe) is not with the events fired, I can
marhall them just fine using (Begin)Invoke. It is with the internal thread
which updates the form itself. The form however was not created by this
animation thread which is only created later, after construction of the
form. It was created by the main UI thread.
In framework 1.1 there was no problem and with framework 2.0 I can just set
Control.CheckForIllegalCrossThreadCalls to false and all is fine again. I
tried to be a good boy though, just to be sure there will be no surprises,
to make it thread-safe.
Marshalling every call to the form's message loop using (Begin)Invoke is
pointless, it defeats the purpose of having a separate animation thread.
Animation got jerky, stalling the main UI thread. So I basically wanted the
form to be created on the animation thread itself.
I may be stupid but it took me a couple of days to come to terms with the
fact that this is impossible. It is like lifting yourself up by your shoe
laces.
Now I was thinking... can I not marshall the control to another thread
instead of marshalling each call to the appropriate thread?
Like a control is created on thread A. Then, when in thread B, I want to
mess with it. Then I want to be able to tell Windows "Hey, this control
which is owned by thread A, please consider it owned by thread B from now
on". And then call its methods from thread B.
This would be so much more convenient in my scenario. Can it be done?
Regards, Martin.