G
Guest
Hi,
[ Using C# in .Net 1.1 ].
I've been struggling with a "hang" in my application all day and I think I
have just worked out why the problem occurs. Please read through and see if
u think this is a bug.
I have a few UI controls that are being updated on a TimerThread ( I check
the "InvokeRequired" and perform the Invoke if required, when I want to
update the control when Im in the TimerThread ). However I was noticing
problems when this occurred as my app would hang. In the debugger I noticed
that just before the hang, the InvokeRequired was returning "False" when it
was being called from the TimerThread - when it should have being returning
"True".
After much swearing etc.. and many hours, I eventually managed to determine
that the "_CreateThreadId" property for my controls was changing **after**
that control was accessed by the TimerThread. I think that this may all be
being caused by the Control.Handle property. It seems as though the handle
isnt actually assigned until you request it, and when you do it overwrites
the "_CreateThreadId" with the ThreadID of the thread that was running when
the Handle was requested. As such this causes the InvokeRequired method to
return the wrong value and then the app gets screwed when the control is
attempted to be updated from the 2 different threads.
Is this a bug ?
As a very simple workaround I request "myControl.Handle" straight after
creating the control and this gets rid of the problem - even though I am not
actually doing anything with it!! A quick workaround, but a horrid problem!!
RichS
[ Using C# in .Net 1.1 ].
I've been struggling with a "hang" in my application all day and I think I
have just worked out why the problem occurs. Please read through and see if
u think this is a bug.
I have a few UI controls that are being updated on a TimerThread ( I check
the "InvokeRequired" and perform the Invoke if required, when I want to
update the control when Im in the TimerThread ). However I was noticing
problems when this occurred as my app would hang. In the debugger I noticed
that just before the hang, the InvokeRequired was returning "False" when it
was being called from the TimerThread - when it should have being returning
"True".
After much swearing etc.. and many hours, I eventually managed to determine
that the "_CreateThreadId" property for my controls was changing **after**
that control was accessed by the TimerThread. I think that this may all be
being caused by the Control.Handle property. It seems as though the handle
isnt actually assigned until you request it, and when you do it overwrites
the "_CreateThreadId" with the ThreadID of the thread that was running when
the Handle was requested. As such this causes the InvokeRequired method to
return the wrong value and then the app gets screwed when the control is
attempted to be updated from the 2 different threads.
Is this a bug ?
As a very simple workaround I request "myControl.Handle" straight after
creating the control and this gets rid of the problem - even though I am not
actually doing anything with it!! A quick workaround, but a horrid problem!!
RichS