Re: Monitoring Threads

Kelly Baker <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <002e01c771f5$96e7fa60$c4b7ef20$@com>
Thanks for this info.  How do I get around this in the dll?  Peter Ritchie
said to use a System.Forms.Timer.  Can I use that in a dll that does not
have a GUI?

-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps and
controls [mailto:[email protected]] On Behalf Of Patrick
Steele
Sent: Wednesday, March 28, 2007 10:05 PM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Monitoring Threads

The System.Timers.Timer Elapsed event is run on a ThreadPool thread.  So
yes, if you start a BackgroundWorker in the Elapsed event, your running
on thread different than the main UI thread.

--
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: Wednesday, March 28, 2007 10:09 PM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Monitoring Threads


I'm trying NOT to call RunWorkerAsync from a background thread.  I am
running it in a System.Timers.Timer elapsed event.  Does the Timer
automatically run in a different thread?  That's what I wanted to find
out by monitoring what thread running what routines.  Is there a call
that will give me the thread ID as shown in the Thread window of the
debugger?

Thanks,
Kelly

-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
Peter Ritchie
Sent: Wednesday, March 28, 2007 8:28 PM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Monitoring Threads

The completed and progress events are called on the same thread that
calls the RunWorkerAsync method.  If you call the RunWorkerAsync method
on a thread other than the GUI thread then you'll get cross-threading
exceptions when you try to access Control data from within those event
handlers.

Why are you calling RunWorkerAsync from a background thread?  I.e. what
are you trying to accomplish?  There's several ways to approach this,
I'm just trying to find out what way would be best.


On Wed, 28 Mar 2007 19:37:08 -0500, Kelly Baker
<[email protected]> wrote:

>I am still working on that dll that runs a process in a different
>thread, then raises a NewData event for the calling executable.  I have

>redone it using the BackgroundWorker class to do my threading.  I have
>a System.Timers.Timer object that runs the RunWorkerAsync method.  In
>the RunWorkerCompleted event I raise the NewData event.  But the
>executable still raises the cross-threading error when I try to update
>the form controls.  Is there a way to programmatically get the thread
>ID that is displayed on the Threads debug window?  I would like to log
>what thread is active with each operation until I can find where my
>problem is.
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.