List all process threads in current running processes : Process « Development « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Development » Process 
14.15.12.List all process threads in current running processes
using System;
using System.Diagnostics;

class MainClass
{
   public static void Main()
   {
      Process[] allProcs = Process.GetProcesses();

      foreach(Process proc in allProcs)
      {
         ProcessThreadCollection myThreads = proc.Threads;
         Console.WriteLine("process: {0},  id: {1}", proc.ProcessName, proc.Id);

         foreach(ProcessThread pt in myThreads)
         {
            Console.WriteLine("  thread:  {0}", pt.Id);
            Console.WriteLine("    started: {0}", pt.StartTime.ToString());
            Console.WriteLine("    CPU time: {0}", pt.TotalProcessorTime);
            Console.WriteLine("    priority: {0}", pt.BasePriority);
            Console.WriteLine("    thread state: {0}", pt.ThreadState.ToString())
         }
      }
   }
}
process: explorer,  id: 1636
  thread:  1640
    started: 16/03/2007 8:42:07 PM
    CPU time: 00:01:31.1250000
    priority: 8
    thread state: Wait
  thread:  1932
    started: 16/03/2007 8:42:10 PM
    CPU time: 00:02:00.9062500
    priority: 9
    thread state: Wait
  thread:  1936
    started: 16/03/2007 8:42:10 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  1944
    started: 16/03/2007 8:42:10 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1952
    started: 16/03/2007 8:42:11 PM
    CPU time: 00:02:51.6093750
    priority: 8
    thread state: Wait
  thread:  400
    started: 16/03/2007 8:42:17 PM
    CPU time: 00:00:10.0781250
    priority: 8
    thread state: Wait
  thread:  612
    started: 16/03/2007 8:42:24 PM
    CPU time: 00:00:00
    priority: 15
    thread state: Wait
  thread:  1696
    started: 16/03/2007 8:42:52 PM
    CPU time: 00:00:10
    priority: 10
    thread state: Wait
  thread:  2864
    started: 16/03/2007 8:44:36 PM
    CPU time: 00:42:13.9218750
    priority: 8
    thread state: Wait
  thread:  2868
    started: 16/03/2007 8:44:37 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  4032
    started: 20/03/2007 7:32:28 PM
    CPU time: 00:00:00.1250000
    priority: 8
    thread state: Wait
  thread:  208
    started: 23/03/2007 8:22:56 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  2684
    started: 23/03/2007 8:25:29 PM
    CPU time: 00:00:00.0312500
    priority: 8
    thread state: Wait
  thread:  2364
    started: 25/03/2007 12:20:21 PM
    CPU time: 00:00:14.2812500
    priority: 8
    thread state: Wait
  thread:  3964
    started: 25/03/2007 2:25:01 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
process: svchost,  id: 1064
  thread:  1068
    started: 16/03/2007 8:42:03 PM
    CPU time: 00:00:00.6562500
    priority: 8
    thread state: Wait
  thread:  1088
    started: 16/03/2007 8:42:03 PM
    CPU time: 00:00:00.0468750
    priority: 8
    thread state: Wait
  thread:  1092
    started: 16/03/2007 8:42:03 PM
    CPU time: 00:00:00.0781250
    priority: 8
    thread state: Wait
  thread:  1096
    started: 16/03/2007 8:42:03 PM
    CPU time: 00:00:39.6093750
    priority: 8
    thread state: Wait
  thread:  1100
    started: 16/03/2007 8:42:03 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  1132
    started: 16/03/2007 8:42:03 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1240
    started: 16/03/2007 8:42:04 PM
    CPU time: 00:00:00.0312500
    priority: 8
    thread state: Wait
  thread:  1548
    started: 16/03/2007 8:42:07 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1560
    started: 16/03/2007 8:42:07 PM
    CPU time: 00:00:00.1875000
    priority: 8
    thread state: Wait
  thread:  1688
    started: 16/03/2007 8:42:08 PM
    CPU time: 00:00:00.0468750
    priority: 8
    thread state: Wait
  thread:  1692
    started: 16/03/2007 8:42:08 PM
    CPU time: 00:00:02.0468750
    priority: 8
    thread state: Wait
  thread:  1700
    started: 16/03/2007 8:42:08 PM
    CPU time: 00:00:01.5312500
    priority: 8
    thread state: Wait
  thread:  1704
    started: 16/03/2007 8:42:08 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1708
    started: 16/03/2007 8:42:08 PM
    CPU time: 00:00:00.2500000
    priority: 8
    thread state: Wait
  thread:  1772
    started: 16/03/2007 8:42:08 PM
    CPU time: 00:00:17
    priority: 8
    thread state: Wait
  thread:  1820
    started: 16/03/2007 8:42:10 PM
    CPU time: 00:01:06.7031250
    priority: 8
    thread state: Wait
  thread:  148
    started: 16/03/2007 8:42:15 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  380
    started: 16/03/2007 8:42:17 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  392
    started: 16/03/2007 8:42:17 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  396
    started: 16/03/2007 8:42:17 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  424
    started: 16/03/2007 8:42:18 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  628
    started: 16/03/2007 8:42:24 PM
    CPU time: 00:00:00.1093750
    priority: 8
    thread state: Wait
  thread:  1180
    started: 16/03/2007 8:42:25 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  1184
    started: 16/03/2007 8:42:25 PM
    CPU time: 00:00:00.0781250
    priority: 8
    thread state: Wait
  thread:  1256
    started: 16/03/2007 8:42:26 PM
    CPU time: 00:00:01.0156250
    priority: 8
    thread state: Wait
  thread:  1288
    started: 16/03/2007 8:42:26 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1076
    started: 16/03/2007 8:42:26 PM
    CPU time: 00:00:00.0156250
    priority: 15
    thread state: Wait
  thread:  756
    started: 16/03/2007 8:42:26 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  812
    started: 16/03/2007 8:42:26 PM
    CPU time: 00:00:00.0312500
    priority: 8
    thread state: Wait
  thread:  1452
    started: 16/03/2007 8:42:29 PM
    CPU time: 00:00:01
    priority: 8
    thread state: Wait
  thread:  1456
    started: 16/03/2007 8:42:29 PM
    CPU time: 00:00:00.1093750
    priority: 8
    thread state: Wait
  thread:  1480
    started: 16/03/2007 8:42:33 PM
    CPU time: 00:00:00.0468750
    priority: 8
    thread state: Wait
  thread:  1516
    started: 16/03/2007 8:42:33 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1312
    started: 16/03/2007 8:42:33 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1080
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  940
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  1160
    started: 16/03/2007 8:42:50 PM
    CPU time: 00:00:00.0156250
    priority: 9
    thread state: Wait
  thread:  1364
    started: 16/03/2007 8:42:50 PM
    CPU time: 00:00:00.0625000
    priority: 8
    thread state: Wait
  thread:  1048
    started: 16/03/2007 8:42:50 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  1368
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00.9687500
    priority: 8
    thread state: Wait
  thread:  1372
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 9
    thread state: Wait
  thread:  1460
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 9
    thread state: Wait
  thread:  1404
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  968
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1536
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1496
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1488
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1500
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1860
    started: 16/03/2007 8:42:51 PM
    CPU time: 00:00:00.0468750
    priority: 8
    thread state: Wait
  thread:  2136
    started: 16/03/2007 8:42:52 PM
    CPU time: 00:00:00.0625000
    priority: 8
    thread state: Wait
  thread:  2148
    started: 16/03/2007 8:42:52 PM
    CPU time: 00:00:01.1406250
    priority: 8
    thread state: Wait
  thread:  2160
    started: 16/03/2007 8:42:53 PM
    CPU time: 00:00:00.5156250
    priority: 8
    thread state: Wait
  thread:  2304
    started: 16/03/2007 8:42:59 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1600
    started: 17/03/2007 8:42:08 AM
    CPU time: 00:00:01.6250000
    priority: 8
    thread state: Wait
  thread:  1972
    started: 17/03/2007 10:17:18 AM
    CPU time: 00:00:01.0156250
    priority: 8
    thread state: Wait
  thread:  1040
    started: 19/03/2007 7:39:40 PM
    CPU time: 00:00:00
    priority: 9
    thread state: Wait
  thread:  160
    started: 20/03/2007 6:05:14 AM
    CPU time: 00:00:01.9218750
    priority: 8
    thread state: Wait
  thread:  1024
    started: 20/03/2007 9:06:56 PM
    CPU time: 00:00:00.0781250
    priority: 8
    thread state: Wait
  thread:  3660
    started: 23/03/2007 8:42:51 PM
    CPU time: 00:00:00.1406250
    priority: 8
    thread state: Wait
  thread:  2072
    started: 24/03/2007 2:36:56 AM
    CPU time: 00:00:00.2031250
    priority: 8
    thread state: Wait
  thread:  732
    started: 25/03/2007 11:18:24 AM
    CPU time: 00:00:00.0781250
    priority: 8
    thread state: Wait
  thread:  3436
    started: 25/03/2007 11:37:24 AM
    CPU time: 00:00:00.0781250
    priority: 8
    thread state: Wait
  thread:  2016
    started: 25/03/2007 12:16:30 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  560
    started: 25/03/2007 12:18:49 PM
    CPU time: 00:00:00.1718750
    priority: 8
    thread state: Wait
  thread:  2856
    started: 25/03/2007 2:10:18 PM
    CPU time: 00:00:00.0468750
    priority: 8
    thread state: Wait
  thread:  2528
    started: 25/03/2007 2:14:25 PM
    CPU time: 00:00:00.0625000
    priority: 8
    thread state: Wait
  thread:  436
    started: 25/03/2007 2:16:38 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  3792
    started: 25/03/2007 2:17:12 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  4088
    started: 25/03/2007 2:17:12 PM
    CPU time: 00:00:00.0156250
    priority: 8
    thread state: Wait
  thread:  1828
    started: 25/03/2007 2:18:54 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  3148
    started: 25/03/2007 2:22:27 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  2320
    started: 25/03/2007 2:24:35 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
process: svchost,  id: 884
  thread:  888
    started: 16/03/2007 8:42:00 PM
    CPU time: 00:00:00.0312500
    priority: 8
    thread state: Wait
  thread:  908
    started: 16/03/2007 8:42:01 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  916
    started: 16/03/2007 8:42:01 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1000
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  944
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  948
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1988
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1984
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1980
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1996
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1992
    started: 16/03/2007 8:42:49 PM
    CPU time: 00:00:00.9062500
    priority: 8
    thread state: Wait
  thread:  2632
    started: 16/03/2007 8:44:10 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  3684
    started: 18/03/2007 4:15:30 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  3652
    started: 18/03/2007 4:15:30 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  1084
    started: 25/03/2007 9:31:28 AM
    CPU time: 00:00:00.0937500
    priority: 8
    thread state: Wait
  thread:  3008
    started: 25/03/2007 1:54:53 PM
    CPU time: 00:00:00
    priority: 8
    thread state: Wait
  thread:  3456
    started: 25/03/2007 2:12:34 PM
    CPU time: 00:00:00
^CTerminate batch job (Y/N)? n
14.15.Process
14.15.1.Starting Processes by using ProcessStartInfo
14.15.2.Starting a new process.
14.15.3.Detecting Process Completion
14.15.4.Redirecting Process Output
14.15.5.Get all processes on local machine
14.15.6.Enumerate over threads in a given PID
14.15.7.Enumerate over mods in a given PID
14.15.8.Launch / kill a process
14.15.9.Threads in Current Process
14.15.10.Property of current Process
14.15.11.Change priority for current process
14.15.12.List all process threads in current running processes
14.15.13.All current running processes
14.15.14.Listing processes on a remote machine
14.15.15.Get processes by name
14.15.16.Get all processes running on the local computer
14.15.17.Get all processes running on the remote computer
14.15.18.Get a process on the local computer, using the process id
14.15.19.Get a process on a remote computer, using the process id
14.15.20.Display the process statistics until the user closes the program
14.15.21.Uses the ProcessStartInfo class to start new processes, both in a minimized mode
14.15.22.Using an IP address to specify the machineName parameter
14.15.23.Start a Web page using a browser associated with .html and .asp files
14.15.24.Using the computer alias (do not precede with "\\")
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.