Få en lista av spring bearbetar i C#
System.Diagnostics-namespacen innehåller fungerar som låter dig klara av bearbetar, trådar, eventlogs och information om kapacitet.
System.Diagnostics.Processna anmärker ger dig tar fram till funktionsduglighet möjliggöra dig för att klara av systemet bearbetar. Vi ska bruk som detta anmärker för att få en lista av spring bearbetar.
Tillfoga detta fodrar till ditt använda listar:
använda System.Diagnostics;
Nu kan du få en lista av bearbetar med metoden för Process.GetProcesses (), som sett i detta exempel:
Bearbeta [] processlisten = Process.GetProcesses ();
foreach (processaa theprocess i processlist) {
Console.WriteLine (” bearbeta: {0} LEGITIMATION: {1}”, theprocess.ProcessName, theprocess. ID);
}
Någon intressant rekvisita av det processaa anmärker:
p.StartTime (Shows tiden startade det processaa)
p.TotalProcessorTime (Shows beloppet av CPU - tajma det processaa har tagit),
p.Threads (ger sig tar fram till samlingen av trådar i det processaa),
.NET-ramen gör egentligen saker enkel!

Dagligen e-postuppdateringar
Du kan få vår hur-till artiklar i din inbox varje dag för fritt. Skriv in precis din nedanföra känt och e-post:


Simple Correction: (at least to fix mine)
Process processlist = Process.GetProcesses();
should be:
Process[] processlist = Process.GetProcesses();
Using the original posting way gave ‘Cannot implicitly convert’ errors, due to Process.GetProcesses() returning an array.
As a side note, make sure to remove and replace the quotes in the Console.Writeline command, if the compiler complains about that statement. The quotes copied as nonstandard quotations on my machine.
Just trying to help others, thanks for the post, I didn’t know about System.Diagnostics until stumbling upon this posting.
Brandon,
Thanks for catching that… typing from memory =)
I’m not sure why, but wordpress converts the quotes to some other quote value. I’ll have to look into that.
Hi.. i want to know which new process the user has requested to open.. i want to control the processes or files to be used by user in C#…
can anyone give up how to achive this.. give the code also if u can…
Hi. I also want to know which you want to know. Please help me!! I want to control the processes which one is open or close???
I am creating a process using some arguments and once the process start I wanted to take a look at the arguments. How do I do that? I have tried using process.StartInfo.Arguments and it didn’t work. Please help!!!
is there any way to track how much time a person is working on a particular file
Hi, Is there a way to know how much CPU each thread for a process(say, w3wp.exe) uses?? In other words, w3wp process creates N no. of threads and I want to know exactly how much CPU each thread is using for this particular process.
is there any way to spit out the command line arguments that were used to fire the given process?
likie for explorer.exe it would show”C:\WINDOWS\Explorer.EXE” and mmc.exe would show ” C:\WINDOWS\system32\perfmon.msc /s”
I can see these values using SysInternals process explorer so i’m hoping I can get them using .Net somehow. CommanArgument doesn’t seem to be an available property on the Process class.
Its really a great job..I keep on wasting 3 Hrs to search what you guys are done here..
Thanks a lot..
Asem Ibohal
How can I get these running process and add to a collection using LINQ ?
Say, u have a class SystemData(double,string,double,double). You can add the Process information using Linq as :
public systemdata(): base()
{
//Add data here
string P_NAME; //process name
double P_ID; //process ID
double P_MEM; //memory Usages
double X_axis=1;
var procname = from n in Process.GetProcesses()
select n;
foreach (var Pname in procname)
{
P_ID = Pname.Id;
P_MEM = Pname.WorkingSet64 / 1024;
P_NAME = Pname.ProcessName;
Add(new SystemData(P_ID, P_NAME, P_MEM,X_axis));
X_axis ++;
}
}
For complete sample, You can mail me at : iamibohal@yahoo.com
This is great. But I do have one question.
How would I get an event when a process is started or ended?
Basicly, I am trying to make my own taskbar in C#.
how we can selection to choice only proceses running?
Process.GetCurrentProcess();
*My bad – Process[] processlist = Process.GetProcesses();
Ok, so we have a list of processes, and I’m particularly interested in the WINWORD one… So how can I turn that into my private Microsoft.Office.Interop.Word.ApplicationClass _Word object so that I can pull its levers n shiz?
it outputs the result I wanted. but at the end it throws the error
explorer: 2656: Tuesday, October 06, 2009 1:48:15 PM
svchost: 960: Tuesday, October 06, 2009 1:45:15 PM
ConsoleApplication1.vshost: 5676: Thursday, October 08, 2009 10:16:22 AM
smax4pnp: 2916: Tuesday, October 06, 2009 1:48:29 PM
RunRM: 3860: Tuesday, October 06, 2009 1:48:38 PM
Error: System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 20