Re: Do-Nothing WinForm App Using 4 Threads?



"gsimmons" <simmons.garry@xxxxxxxxx> wrote in message news:1168870674.106157.29190@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I've been researching multi-threaded WinForms apps and thread
synchronization stuff for a couple days since I'm working on
refactoring a multi-threaded GUI app at work and want to be sure it's
rock solid/thread-safe. I've seen all the posts about using BeginInvoke
to have worker threads interact with the UI. My question is this:

I created a plain old Windows Form application (VS.NET 2005) with a
blank form, built it (release build), ran it from Windows Explorer and
Task Manager claims the application is using four threads. What are
they? Obviously one is the main app/UI. What are the others?

I then added a Windows Timer control to the form and updated a label
every second. Still four threads. I expected a timer to be on its own
thread even though it posts "tick" events to the UI message
loop/thread.

I removed the Windows Timer and replaced it with a System Timer which
runs "tick" events on a different thread, yet the thread count still
stays at four. Huh?

Is there a built-in thread pool with a few workers hanging around to do
timers and stuff? What exactly is going on here?
Are those extra threads part of the CLR doing its magic to run the EXE?
Other?

My next question will be how many threads remoting (inter-process on
the same PC) adds to the mix. The UI app I'm refactoring makes use of
several remote objects (running methods and receiving events with
data). I'm guessing there is a thread for each proxy/socket to handle
marshalling stuff. And the event handling from remote objects
supposedly grabs a thread from the thread pool. Inquiring minds what to
really KNOW what's going on under the hood.

Pointers to good articles and/or books welcome. Spend the last weekend
Googling and reading...

Thanks!



A managed application always starts with a minimum of 3 threads:
1 is the main thread
2 is the debugger thread
3 is the finalizer thread.

A Windows Forms application has at least one additional thread;
4 the GDI+ rendering thread.
Threads 1 and 3 are OS threads, associated with a logical (CLR) thread , while 2 and 4 are just native OS threads created by the CLR, they don't have an associated logical thread.

Non "Windows Forms Timers" are handled by the Threadpool, more exactly their handlers run on an IO completion thread pulled from the pool. It's obvious that you will only notice these threads when they run for at least Taskman's window update interval .
Windows Forms Timer handlers are run on the UI thread, they are simple WM_TIMER handlers.

Willy.



.



Relevant Pages

  • Re: Do-Nothing WinForm App Using 4 Threads?
    ... Windows CE). ... | refactoring a multi-threaded GUI app at work and want to be sure it's ... I expected a timer to be on its own ... And the event handling from remote objects ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Dual-core systems - AMD - Windows Vista
    ... recall that NTP on Windows uses some interpolation technique to overcome ... timer granularity, and that the interpolation used a CPU counter. ... Windows Vista. ... Windows Vista differ from Windows XP so as to affect NTP, ...
    (comp.protocols.time.ntp)
  • Re: Need info on Windows Timers
    ... > 1) How exactly Windows executes the timer callback. ... > From the articles I read, ... > timer interrupt. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: how to differentiate a single click from a double click in CTreeviewCtrl
    ... Part of the problem of "specifications" is that if a specifcation is written by someone ... who is clueless about Windows, GUI interfaces in general, and programming, they will ... Note that if you use a timer, you have to set it to ~1.25 * the double-click time (which ... This is usually selection. ...
    (microsoft.public.vc.mfc)
  • Re: NEED HELP -- Windows Explorer locking up
    ... contextmenu handlers (non-ms) ... Windows XP Shell/User ... > For starters, I cannot right-click an icon on my desktop to create a> shortcut. ...
    (microsoft.public.windowsxp.help_and_support)