Which thread was a control created on?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way in .NET framework to check which thread a particular windows forms control was created on?

I want to check that a particular control was created on the same thread as my main form, from another arbitrary thread.

I know the "InvokeRequired" property, but I need to marshall the control as a parameter to a method on the main form's thread, and I want to check the thread is OK before I marshall it using myMainForm.Invoke() - as this seems to hang if the control is created on the "wrong" thread.
 
There is some information on how they implement marshalling on my blog.
You'll find the necessary methods there to get the thread that is associated
with a windows handle, and thus it's message pump.

http://weblogs.asp.net/justin_rogers/articles/126345.aspx

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


richlm said:
Is there a way in .NET framework to check which thread a particular windows forms control was created on?

I want to check that a particular control was created on the same thread as my
main form, from another arbitrary thread.
I know the "InvokeRequired" property, but I need to marshall the control as a
parameter to a method on the main form's thread, and I want to check the thread
is OK before I marshall it using myMainForm.Invoke() - as this seems to hang if
the control is created on the "wrong" thread.
 
But this is exactly what InvokeRequired is for. If InvokeRequired returns true then all calls to the control must be marshaled through the use of Invoke because the called control is then created by another thread than the calling thread

Regards, Jakob.
 
Yes - but InvokeRequired checks the thread that the control was created on against the current thread - what I am looking for is to check it against another thread (not the current thread).

Justin's article on this forum thread contains the info - there's a Win32 API function (not managed code).
 
Back
Top