How to get the computer (PC) total threads in C#

1 Answer

0 votes
using System;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Process[] processes = null;
            string machineName = ".";

            try
            {
                processes = Process.GetProcesses(machineName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            int threadscount = 0;
            foreach (Process p in processes)
                 threadscount += p.Threads.Count;

            Console.WriteLine("Total threads: {0}", threadscount); // Total threads: 1577
        }
    }
}

/*
run:
   
Total threads: 1577

*/


answered Mar 12, 2015 by avibootz
...