Re: How to tell what thread is current

Patrick Steele <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <004101c7724b$72640660$6701a8c0@raptor>
I think what you want to do is always calls UpdateProgress, and then
inside UpdateProgress, check your InvokeRequired property to see if you
need to marshal the call back to the UI thread.  It's a pretty simple
pattern (depending on your method signature):

public void UpdateProgress()
{
        if(progressBar.InvokeRequired)
        {
                progressBar.Invoke(new MethodInvoker(UpdateProgress));
                return;
        }

        // update your progress bar
}

Of course, this assumes you're using a progress bar.  Your controls may
vary...  :)

--
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 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?





_________________________________________________________________
Need personalized email and website? Look no further. It's easy with
Doteasy $0 Web Hosting! Learn more at www.doteasy.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.