views:

203

answers:

3

I'm trying to troubleshoot a larger multiprocessing issue -- I suspect a client library is creating a foreground thread, and I'm trying to see if that theory is correct.

In order to do that, I'd like to be able to log a list of all threads in a process, what their state is, and whether they are background or foreground.

I've seen Process.GetCurrentProcess().Threads, but that returns a ProcessThread object, not a System.Thread. ProcessThread doesn't have all of the properties that a System.Thread does.

Is there a way to get the list of System.Threads?

+3  A: 

How about using Sysinternal's ProcMon

As @jvilalta pointed out, Process Explorer is also a good option.

Am
Or their Process Explorer...
TskTsk
Or Process Hacker http://processhacker.sourceforge.net
KingRadical
Note that it's not guaranteed that there will be a separate OS thread (which is what procmon and procexp show) for every CLR thread: see http://stackoverflow.com/questions/466632/how-can-i-get-managed-threads-from-process-getcurrentprocess-threads. So procmon may miss some managed threads. Also note OS threads won't have managed thread information like name and foreground/background: what procmon/procexp show is equivalent to a ProcessThread, which Jeremy says he has already considered and rejected.
itowlson
A: 

You might be able to see these using Process Monitor http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

Mark Redman
+2  A: 

Visual Studio natively has the ability to view all active threads, OR you could use DebugInspector (not sure of the url, sorry).

From C#, not sure how this can be done.

dotnetdev