Re: How to tell what thread is current
Patrick Steele <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <006501c77269$847151a0$6701a8c0@raptor> |
I see. So when InvokeRequired returns false, then the thread you're on is the same thread for the form the control is currently a child of? -- Patrick Steele http://weblogs.asp.net/psteele -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Peter Ritchie Sent: Thursday, March 29, 2007 9:04 PM To: [email protected] Subject: Re: [DOTNET-WINFORMS] How to tell what thread is current Windows only supports a child and a parent being created on the same thread. On Thu, 29 Mar 2007 17:24:57 -0400, Patrick Steele <[email protected]> wrote: >Actually, InvokeRequired will tell you if you're currently in the >thread the *created the control*, not the thread that owns the form. > >-- >Patrick Steele >http://weblogs.asp.net/psteele > > > >-----Original Message----- >From: Discussion forum for developers using Windows Forms to build apps >and controls [mailto:[email protected]] On Behalf Of >Nassar, Anthony >Sent: Thursday, March 29, 2007 5:15 PM >To: [email protected] >Subject: Re: [DOTNET-WINFORMS] How to tell what thread is current > > >You can use the boolean property Control.InvokeRequired on the form; >that will tell you if you're currently in the thread that owns the >form. That's really all you want to know, isn't it? I hope it's not >patronizing to point you to >http://msdn2.microsoft.com/en-us/library/ms951089.aspx. > >-----Original Message----- >From: Discussion forum for developers using Windows Forms to build apps >and controls [mailto:[email protected]] On Behalf Of >Kelly Baker >Sent: Thursday, March 29, 2007 5:11 PM >To: [email protected] >Subject: Re: [DOTNET-WINFORMS] How to tell what thread is current > >I need to know if the current thread is the same as the host form (the >form in which my control is loaded). This function raises an event >which is used to update controls on the form, and if it is not the same >thread as the host form, I need to know. > >I am using a BackgroundWorker for my threading, and if I am not in the >same thread as the form, I can call the UpdateProgress method of the >BackgroundWorker. > > > >Why do you need to know this? > >And how do you define the "host" form? An app could have several forms >visible at a time -- which one is the host form? And what about >mutiple UI threads? > >What is it you're trying to accomplish that needs this information? > >-- >Patrick Steele >http://weblogs.asp.net/psteele > > > >-----Original Message----- >From: Discussion forum for developers using Windows Forms to build apps >and controls [mailto:[email protected]] On Behalf Of >Kelly Baker >Sent: Thursday, March 29, 2007 4:53 PM >To: [email protected] >Subject: [DOTNET-WINFORMS] How to tell what thread is current > > >I have a function in a control that may be called within different >threads. How can I tell if it is on the same thread as the host form?