473,562 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count of system-wide threads?

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!
Feb 11 '07 #1
6 6487
Hi Gunga,
To do this, you need to first import System.Diagnost ic namespace, get the
current processes running on your machine and retrieve the total threadcounts
of each process.
See me code below,

using System.Diagnost ics;
Process[] processList = Process.GetProc esses();
int threadCount = 0;
foreach (Process proc in processList)
{
threadCount = threadCount + proc.Threads.Co unt;
}

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!
Feb 12 '07 #2
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
Feb 12 '07 #3
"Gunga Din" <nonewrote in message news:0c******** *************@g iganews.com...
>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.Diagnost ics the counter to read is
System/Threads.

Willy.

Feb 12 '07 #4
"Cyber Sannyasi" <Cy***********@ discussions.mic rosoft.comwrote in message
news:20******** *************** ***********@mic rosoft.com...
Hi Gunga,
To do this, you need to first import System.Diagnost ic namespace, get the
current processes running on your machine and retrieve the total threadcounts
of each process.
See me code below,

using System.Diagnost ics;
Process[] processList = Process.GetProc esses();
int threadCount = 0;
foreach (Process proc in processList)
{
threadCount = threadCount + proc.Threads.Co unt;
}

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

Feb 12 '07 #5
"Marc Gravell" <ma**********@g mail.comwrote in message
news:Op******** *****@TK2MSFTNG P04.phx.gbl...
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.Diagnost ics 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.

Feb 12 '07 #6

"Cyber Sannyasi" <Cy***********@ discussions.mic rosoft.comwrote in message
news:20******** *************** ***********@mic rosoft.com...
Hi Gunga,
To do this, you need to first import System.Diagnost ic namespace, get the
current processes running on your machine and retrieve the total
threadcounts
of each process.
See me code below,

using System.Diagnost ics;
Process[] processList = Process.GetProc esses();
int threadCount = 0;
foreach (Process proc in processList)
{
threadCount = threadCount + proc.Threads.Co unt;
}

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...
Feb 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2090
by: Niklas E | last post by:
Does anyone know how to get all nodes in a xml-document that start with a certain text? In my case I want to count all suppliers ( <id>Supplier*</id> ) <root> <customer> <name>ABC</name> <id>Supplier123</id> </customer>
5
5906
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int Count { get { return 0; }
0
4668
by: Ireneus Broncel | last post by:
I have a class which reads Groups and Users from ActiveDirectory. The Problem is, that i have about 10000 rows as product. When I am trying to read the "memberOf" Objects out of this field i get allways different count of rows. If anybody knows something about this kind of problem, I would appreciate any help. Thx.
3
4581
by: jason | last post by:
Hello. I've got this simple collection populate code I downloaded from the net (sorry can't find source now) I'm trying to test, but I can't seem to get it to work. Any help would be greatly appreciated. I've compiled the following VB.NET into a DLL: Imports System Imports System.Data Imports System.Data.SqlClient Imports...
6
6684
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
68
6770
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
4
3083
by: Peter W Johnson | last post by:
Hi guys, I have a problem with a datagrid record count. Here is the code:- <snip> Public Class frmMerchantDeposit Inherits System.Windows.Forms.Form Dim myconnection As New Odbc.OdbcConnection("DSN=database")
2
2165
by: GoCoogs | last post by:
I'm trying to count how many items are in a dynamic collection. This is the code I have so far. *** Begin Code *** Public Class Rule Private _rulevars As RuleVarsCollection Private _rulename As String Public Property Name() As String Get
12
3862
by: KWSW | last post by:
Got this assignment due a few weeks later and since I am done with the up coming assignment, decided to try out the next one early rather than rush later. First part of it requires me to do a character count on a text document which i will have to use huffman coding to encode. Below is my code that i created to count and display the characters...
2
23160
by: leegold58 | last post by:
Newbie question must of been asked before but: How do I count the number of tables in a database? Without VB, prefer to use SQL or the Access GUI somehow. Thanks. Lee g.
0
7658
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7874
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5198
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
907
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.