Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Process.UserProcessorTime Property

Definition

Namespace:
System.Diagnostics
Assemblies:
netstandard.dll, System.Diagnostics.Process.dll
Assembly:
System.Diagnostics.Process.dll
Assembly:
System.dll
Assembly:
netstandard.dll
Source:
Process.Linux.cs
Source:
Process.Linux.cs
Source:
Process.Linux.cs
Source:
Process.Linux.cs
Source:
Process.Linux.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets the user processor time for this process.

public:
 property TimeSpan UserProcessorTime { TimeSpan get(); };
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public TimeSpan UserProcessorTime { get; }
public TimeSpan UserProcessorTime { get; }
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.UserProcessorTime : TimeSpan
member this.UserProcessorTime : TimeSpan
Public ReadOnly Property UserProcessorTime As TimeSpan

Property Value

A TimeSpan that indicates the amount of time that the associated process has spent running code inside the application portion of the process (not inside the operating system core).

Attributes

Exceptions

You are attempting to access the UserProcessorTime property for a process that is running on a remote computer. This property is available only for processes that are running on the local computer.

Examples

The following example starts an instance of Notepad. The example then retrieves and displays various properties of the associated process. The example detects when the process exits, and displays the process's exit code.

using System;
using System.Diagnostics;

namespace ProcessSample
{
 class ProcessMonitorSample
 {
 public static void Main()
 {
 // Define variables to track the peak
 // memory usage of the process.
 long peakPagedMem = 0,
 peakWorkingSet = 0,
 peakVirtualMem = 0;

 // Start the process.
 using (Process myProcess = Process.Start("NotePad.exe"))
 {
 // Display the process statistics until
 // the user closes the program.
 do
 {
 if (!myProcess.HasExited)
 {
 // Refresh the current process property values.
 myProcess.Refresh();

 Console.WriteLine();

 // Display current process statistics.

 Console.WriteLine($"{myProcess} -");
 Console.WriteLine("-------------------------------------");

 Console.WriteLine($" Physical memory usage : {myProcess.WorkingSet64}");
 Console.WriteLine($" Base priority : {myProcess.BasePriority}");
 Console.WriteLine($" Priority class : {myProcess.PriorityClass}");
 Console.WriteLine($" User processor time : {myProcess.UserProcessorTime}");
 Console.WriteLine($" Privileged processor time : {myProcess.PrivilegedProcessorTime}");
 Console.WriteLine($" Total processor time : {myProcess.TotalProcessorTime}");
 Console.WriteLine($" Paged system memory size : {myProcess.PagedSystemMemorySize64}");
 Console.WriteLine($" Paged memory size : {myProcess.PagedMemorySize64}");

 // Update the values for the overall peak memory statistics.
 peakPagedMem = myProcess.PeakPagedMemorySize64;
 peakVirtualMem = myProcess.PeakVirtualMemorySize64;
 peakWorkingSet = myProcess.PeakWorkingSet64;

 if (myProcess.Responding)
 {
 Console.WriteLine("Status = Running");
 }
 else
 {
 Console.WriteLine("Status = Not Responding");
 }
 }
 }
 while (!myProcess.WaitForExit(1000));

 Console.WriteLine();
 Console.WriteLine($" Process exit code : {myProcess.ExitCode}");

 // Display peak memory statistics for the process.
 Console.WriteLine($" Peak physical memory usage : {peakWorkingSet}");
 Console.WriteLine($" Peak paged memory usage : {peakPagedMem}");
 Console.WriteLine($" Peak virtual memory usage : {peakVirtualMem}");
 }
 }
 }
}
open System.Diagnostics

// Define variables to track the peak
// memory usage of the process.
let mutable peakPagedMem = 0L
let mutable peakWorkingSet = 0L
let mutable peakVirtualMem = 0L

// Start the process.
use myProcess = Process.Start "NotePad.exe"

// Display the process statistics until
// the user closes the program.
while myProcess.WaitForExit 1000 |> not do
 if not myProcess.HasExited then
 // Refresh the current process property values.
 myProcess.Refresh()

 printfn ""

 // Display current process statistics.

 printfn $"{myProcess} -"
 printfn "-------------------------------------"

 printfn $" Physical memory usage : {myProcess.WorkingSet64}"
 printfn $" Base priority : {myProcess.BasePriority}"
 printfn $" Priority class : {myProcess.PriorityClass}"
 printfn $" User processor time : {myProcess.UserProcessorTime}"
 printfn $" Privileged processor time : {myProcess.PrivilegedProcessorTime}"
 printfn $" Total processor time : {myProcess.TotalProcessorTime}"
 printfn $" Paged system memory size : {myProcess.PagedSystemMemorySize64}"
 printfn $" Paged memory size : {myProcess.PagedMemorySize64}"

 // Update the values for the overall peak memory statistics.
 peakPagedMem <- myProcess.PeakPagedMemorySize64
 peakVirtualMem <- myProcess.PeakVirtualMemorySize64
 peakWorkingSet <- myProcess.PeakWorkingSet64

 if myProcess.Responding then
 printfn "Status = Running"
 else
 printfn "Status = Not Responding"

printfn ""
printfn $" Process exit code : {myProcess.ExitCode}"

// Display peak memory statistics for the process.
printfn $" Peak physical memory usage : {peakWorkingSet}"
printfn $" Peak paged memory usage : {peakPagedMem}"
printfn $" Peak virtual memory usage : {peakVirtualMem}"
Imports System.Diagnostics

Namespace ProcessSample
 Class ProcessMonitorSample

 Public Shared Sub Main()

 ' Define variables to track the peak
 ' memory usage of the process.
 Dim peakPagedMem As Long = 0
 Dim peakWorkingSet As Long = 0
 Dim peakVirtualMem As Long = 0

 ' Start the process.
 Using myProcess = Process.Start("NotePad.exe")

 ' Display process statistics until
 ' the user closes the program.
 Do

 If Not myProcess.HasExited Then

 ' Refresh the current process property values.
 myProcess.Refresh()

 Console.WriteLine()

 ' Display current process statistics.

 Console.WriteLine($"{myProcess} -")
 Console.WriteLine("-------------------------------------")

 Console.WriteLine($" Physical memory usage : {myProcess.WorkingSet64}")
 Console.WriteLine($" Base priority : {myProcess.BasePriority}")
 Console.WriteLine($" Priority class : {myProcess.PriorityClass}")
 Console.WriteLine($" User processor time : {myProcess.UserProcessorTime}")
 Console.WriteLine($" Privileged processor time : {myProcess.PrivilegedProcessorTime}")
 Console.WriteLine($" Total processor time : {myProcess.TotalProcessorTime}")
 Console.WriteLine($" Paged system memory size : {myProcess.PagedSystemMemorySize64}")
 Console.WriteLine($" Paged memory size : {myProcess.PagedMemorySize64}")

 ' Update the values for the overall peak memory statistics.
 peakPagedMem = myProcess.PeakPagedMemorySize64
 peakVirtualMem = myProcess.PeakVirtualMemorySize64
 peakWorkingSet = myProcess.PeakWorkingSet64

 If myProcess.Responding Then
 Console.WriteLine("Status = Running")
 Else
 Console.WriteLine("Status = Not Responding")
 End If
 End If
 Loop While Not myProcess.WaitForExit(1000)

 Console.WriteLine()
 Console.WriteLine($" Process exit code : {myProcess.ExitCode}")

 ' Display peak memory statistics for the process.
 Console.WriteLine($" Peak physical memory usage of the process : {peakWorkingSet}")
 Console.WriteLine($" Peak paged memory usage of the process : {peakPagedMem}")
 Console.WriteLine($" Peak virtual memory usage of the process : {peakVirtualMem}")
 End Using
 End Sub
 End Class
End Namespace

Applies to

See also


Feedback

Was this page helpful?