PC Review


Reply
Thread Tools Rate Thread

Count of system-wide threads?

 
 
Gunga Din
Guest
Posts: n/a
 
      11th Feb 2007
I must be missing it somehow...

I need to count the number of threads running, not just those started by my
application. Rather like the Task Manager, I would like to get the total
number of threads that are active.

What would be the most reliable way to obtain this number?

Thanks!


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q3liZXIgU2Fubnlhc2k=?=
Guest
Posts: n/a
 
      12th Feb 2007
Hi Gunga,
To do this, you need to first import System.Diagnostic namespace, get the
current processes running on your machine and retrieve the total threadcounts
of each process.
See me code below,

using System.Diagnostics;


Process[] processList = Process.GetProcesses();
int threadCount = 0;
foreach (Process proc in processList)
{
threadCount = threadCount + proc.Threads.Count;
}

The threadCount gives you the final count of total number of active threads
on your machine...
Hope this helps!!



--
Thinathayalan Ganesan, MCAD


"Gunga Din" wrote:

> I must be missing it somehow...
>
> I need to count the number of threads running, not just those started by my
> application. Rather like the Task Manager, I would like to get the total
> number of threads that are active.
>
> What would be the most reliable way to obtain this number?
>
> Thanks!
>
>
>

 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      12th Feb 2007
Note also that in 2.0 onwards managed threads don't always have a 1:1
mapping to system (process) threads. I only mention this in case you
need to account for some unexpected results.

Marc


 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      12th Feb 2007
"Gunga Din" <none> wrote in message news:0cKdnSR0p_IE-(E-Mail Removed)...
>I must be missing it somehow...
>
> I need to count the number of threads running, not just those started by my application.
> Rather like the Task Manager, I would like to get the total number of threads that are
> active.
>
> What would be the most reliable way to obtain this number?
>
> Thanks!
>



Read the performance counters using System.Diagnostics the counter to read is
System/Threads.

Willy.

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      12th Feb 2007
"Cyber Sannyasi" <(E-Mail Removed)> wrote in message
news:2063C2F7-F933-4FD2-A275-(E-Mail Removed)...
> Hi Gunga,
> To do this, you need to first import System.Diagnostic namespace, get the
> current processes running on your machine and retrieve the total threadcounts
> of each process.
> See me code below,
>
> using System.Diagnostics;
>
>
> Process[] processList = Process.GetProcesses();
> int threadCount = 0;
> foreach (Process proc in processList)
> {
> threadCount = threadCount + proc.Threads.Count;
> }
>
> The threadCount gives you the final count of total number of active threads
> on your machine...
> Hope this helps!!


No need to enumerate the running processes, just need to read the System/Threads performnace
counter.

Willy.
..

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      12th Feb 2007
"Marc Gravell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Note also that in 2.0 onwards managed threads don't always have a 1:1 mapping to system
> (process) threads. I only mention this in case you need to account for some unexpected
> results.
>
> Marc
>

Actually this is only true when managed code hosted in SQL2005, an environment which doesn't
allow (by default) to call System.Diagnostics methods anyway. The option to map fibers to
managed threads has not been implemented in V2 of the CLR, and AFAIK there are no direct
plans to implement this in version next either.

Willy.



 
Reply With Quote
 
Gunga Din
Guest
Posts: n/a
 
      12th Feb 2007

"Cyber Sannyasi" <(E-Mail Removed)> wrote in message
news:2063C2F7-F933-4FD2-A275-(E-Mail Removed)...
> Hi Gunga,
> To do this, you need to first import System.Diagnostic namespace, get the
> current processes running on your machine and retrieve the total
> threadcounts
> of each process.
> See me code below,
>
> using System.Diagnostics;
>
>
> Process[] processList = Process.GetProcesses();
> int threadCount = 0;
> foreach (Process proc in processList)
> {
> threadCount = threadCount + proc.Threads.Count;
> }
>
> The threadCount gives you the final count of total number of active
> threads
> on your machine...
> Hope this helps!!
>
>
>
> --


Thank you very much!

Exactly what I needed...


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System-wide changes. =?Utf-8?B?VGhlX05ld2JfQXZlbmdlcg==?= Windows XP General 1 4th Sep 2007 05:02 PM
System wide hot key overriding Matt Microsoft C# .NET 1 14th May 2006 11:50 PM
Report Count Wide Range of Categories =?Utf-8?B?RGlhbmFT?= Microsoft Access 8 10th Aug 2005 07:58 PM
How to change the system default printer to Landscape system wide Just Me Microsoft VB .NET 2 6th Jun 2005 11:55 AM
Performance Counter; .NET Locks & Threads - Current Queue Count Bu =?Utf-8?B?UGV0ZXJN?= Microsoft Dot NET Framework 3 2nd Mar 2005 02:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:35 PM.