The System.Diagnostics namespace contains functions that allow you to manage processes, threads, eventlogs and performance information.
The System.Diagnostics.Process object gives you access to functionality enabling you to manage system processes. We will use this object to get a list of running processes.
Add this line to your using list:
using System.Diagnostics;
Now you can get a list of the processes with the Process.GetProcesses() method, as seen in this example:
Process[] processlist = Process.GetProcesses();
Granted, Task Manager will show you the same thing, but there's something about get-process that makes the data easier to look at, even if it's only that you can see a complete list without scrolling. You need to dispose of these junk processes (and you will) but in the meantime you can also kill them. We will use this object to get a list of running processes. Add this line to your using list: using System.Diagnostics; Now you can get a list of the processes with the Process.GetProcesses method, as seen in this example: Process processlist = Process.GetProcesses.
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
Some interesting properties of the Process object:
p.StartTime (Shows the time the process started)
p.TotalProcessorTime (Shows the amount of CPU time the process has taken)
p.Threads ( gives access to the collection of threads in the process)
p.TotalProcessorTime (Shows the amount of CPU time the process has taken)
p.Threads ( gives access to the collection of threads in the process)
The .NET framework really makes things simple!
READ NEXT- › Steam Won’t Support Ubuntu 19.10 and Future Releases
- › How to Make Your Dumb Window Air Conditioner Smart
- › Microsoft’s New Windows Terminal Is Now Available
- › How to Report a Fake Business Listing on Google Maps
- › How Piracy Makes Legal Streaming Services Better