1/29
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Process
A class in the System.Diagnostics namespace that represents and provides access to operating-system processes, allowing C# programs to start, inspect, monitor, wait for, and control processes. Domain: C# → .NET → System.Diagnostics → Operating-System Process Management
Process process = new Process();
Creates a new Process component that can later be associated with or used to start an operating-system process.
Process process = Process.Start("notepad.exe");
Starts the specified application or process and returns a Process object representing the started process when available.
Process process = Process.GetCurrentProcess();
Gets a Process object representing the process in which the current .NET application is running.
Process process = Process.GetProcessById(processId);
Gets the local operating-system process having the specified process ID.
Process[] processes = Process.GetProcesses();
Gets an array containing the processes currently running on the local computer.
Process[] processes = Process.GetProcessesByName("notepad");
Gets the running local processes whose process name matches the specified name.
int id = process.Id;
Gets the unique operating-system process identifier associated with the process.
string name = process.ProcessName;
Gets the name of the process.
DateTime started = process.StartTime;
Gets the date and time at which the associated process started.
TimeSpan cpuTime = process.TotalProcessorTime;
Gets the total processor time consumed by the process.
TimeSpan userTime = process.UserProcessorTime;
Gets the amount of processor time the process has spent executing application-level code in user mode.
TimeSpan privilegedTime = process.PrivilegedProcessorTime;
Gets the amount of processor time the process has spent executing operating-system code in privileged mode.
long memory = process.WorkingSet64;
Gets the amount of physical memory currently associated with the process's working set, expressed in bytes.
long peakMemory = process.PeakWorkingSet64;
Gets the maximum amount of physical working-set memory used by the process during its lifetime, expressed in bytes.
ProcessPriorityClass priority = process.PriorityClass;
Gets the operating-system scheduling priority category associated with the process.
process.PriorityClass = ProcessPriorityClass.High;
Requests that the process use the High scheduling priority class; changing process priority may require appropriate permissions and should be done carefully.
bool finished = process.HasExited;
Gets whether the associated process has terminated.
int code = process.ExitCode;
Gets the value returned when the process terminated; it should be accessed only after the process has exited.
DateTime ended = process.ExitTime;
Gets the time at which the associated process terminated and is available after the process has exited.
process.WaitForExit();
Blocks the current thread until the associated process terminates.
bool exited = process.WaitForExit(5000);
Waits up to 5000 milliseconds for the process to terminate and returns whether it exited within that period.
await process.WaitForExitAsync();
Asynchronously waits for the associated process to terminate without synchronously blocking the calling thread while waiting.
process.Kill();
Forcibly terminates the associated process; this should generally be reserved for situations where normal termination is not possible or appropriate.
process.Kill(entireProcessTree: true);
Requests termination of the associated process and its descendant processes.
process.CloseMainWindow();
Requests that a process with a graphical main window close normally by sending a close request to that window.
process.Refresh();
Discards cached process information so subsequently accessed process properties can retrieve updated values.
process.Exited += Process_Exited;
Registers an event handler that can run when the associated process terminates.
process.EnableRaisingEvents = true;
Enables the Process component to raise its Exited event when the associated operating-system process terminates.
process.Dispose();
Releases resources used by the Process component; disposing the Process object does not itself terminate the operating-system process it represents.