Prenumerera till Hur-Till Geek

Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

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!

| Mer
Denna artikel var ursprungligen skriftlig på 11/23/06 Märkt med: Programmera

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:


Känt:
E-post:

Comments (16)

  1. Brandon

    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.

  2. The Geek

    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.

  3. Syed

    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…

  4. Umit

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

  5. Khan

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

  6. mukesh

    is there any way to track how much time a person is working on a particular file

  7. ssp

    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.

  8. Eric

    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.

  9. Asem

    Its really a great job..I keep on wasting 3 Hrs to search what you guys are done here..
    Thanks a lot..

    Asem Ibohal

  10. Asem

    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

  11. Shaaz

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

  12. dzar

    how we can selection to choice only proceses running?

  13. ChokoMd

    Process.GetCurrentProcess();

  14. ChokoMd

    *My bad – Process[] processlist = Process.GetProcesses();

  15. CodeMunter

    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?

  16. silverback12

    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


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Our Friends
Getting Started


About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
conhost.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.