Class JobObject
Represents a Windows JobObject.
Implements
Inherited Members
Namespace: Fs.Processes.JobObjects
Assembly: Fs.Processes.dll
Syntax
public sealed class JobObject : JobObjectInfo, IDisposable
Constructors
| Improve this Doc View SourceJobObject(Nullable<JobLimits>, Nullable<JobNotifications>)
Creates a new JobObject instance.
Declaration
public JobObject(JobLimits? Limits = default(JobLimits? ), JobNotifications? Notifications = default(JobNotifications? ))
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JobLimits> | Limits | |
System.Nullable<JobNotifications> | Notifications | The JobNotifications to apply to the new JobObject. |
Properties
| Improve this Doc View SourceCurrent
Returns a JobObjectInfo instance for the current process's JobObject, or null
if the current
process is not associated with a JobObject.
Declaration
public static JobObjectInfo Current { get; }
Property Value
Type | Description |
---|---|
JobObjectInfo |
Handle
Gets the SafeJobObjectHandle associated with this instance.
Declaration
public SafeJobObjectHandle Handle { get; }
Property Value
Type | Description |
---|---|
SafeJobObjectHandle |
Idle
Gets a task that completes when the number of active processes decreases to zero.
Declaration
public Task Idle { get; }
Property Value
Type | Description |
---|---|
System.Threading.Tasks.Task |
SupportsCpuRates
Gets a value indicating whether the OS supports CPU rate limits.
Declaration
public static bool SupportsCpuRates { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
SupportsNotifications
Gets a value indicating whether the OS supports JobNotifications.
Declaration
public static bool SupportsNotifications { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceAssignProcess(SafeProcessHandle)
Assigns a process to an existing job object.
Declaration
public void AssignProcess(SafeProcessHandle processHandle)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.Win32.SafeHandles.SafeProcessHandle | processHandle | A handle to the process to associate with the job object. The handle must have PROCESS_SET_QUOTA and PROCESS_TERMINATE access rights. |
AssignProcess(IntPtr)
Assigns a process to an existing job object.
Declaration
public void AssignProcess(IntPtr hProcess)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hProcess | A handle to the process to associate with the job object. The handle must have PROCESS_SET_QUOTA and PROCESS_TERMINATE access rights. |
CreateProcess(CreateProcessInfo)
Creates a new process and assigns the process to the job object.
Declaration
public Process CreateProcess(CreateProcessInfo createProcessInfo)
Parameters
Type | Name | Description |
---|---|---|
CreateProcessInfo | createProcessInfo | The CreateProcessInfo that contains information this is used to start the process, including the file name and any command-line arguments. |
Returns
Type | Description |
---|---|
Process | A Process instance that represents the newly created process. |
CreateProcess(CreateProcessInfo, ProcessOptions)
Creates a new process and assigns the process to the job object.
Declaration
public Process CreateProcess(CreateProcessInfo createProcessInfo, ProcessOptions processOptions)
Parameters
Type | Name | Description |
---|---|---|
CreateProcessInfo | createProcessInfo | The CreateProcessInfo that contains information this is used to start the process, including the file name and any command-line arguments. |
ProcessOptions | processOptions | A set of ProcessOptions that controls how the new process is created. |
Returns
Type | Description |
---|---|
Process | A Process instance that represents the newly created process. |
Dispose()
Releases all resources associated with the instance.
Declaration
public void Dispose()
GrantUserHandleAccess(IntPtr, Boolean)
Grants or denies access to a handle to a User object to a job that has a user-interface restrictions. When access is granted, all processes associated with the job can subsequently recognize and use the handle. When access is denied, the processes can no longer use the handle.
Declaration
public void GrantUserHandleAccess(IntPtr objectHandle, bool allowAccess = true)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | objectHandle | A handle to the User object. |
System.Boolean | allowAccess |
|
GrantUserHandleAccess(SafeHandle, Boolean)
Grants or denies access to a handle to a User object to a job that has a user-interface restrictions. When access is granted, all processes associated with the job can subsequently recognize and use the handle. When access is denied, the processes can no longer use the handle.
Declaration
public void GrantUserHandleAccess(SafeHandle objectHandle, bool allowAccess = true)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.InteropServices.SafeHandle | objectHandle | A handle to the User object. |
System.Boolean | allowAccess |
|
Kill(Int32)
Terminate all processes currently associated with the job. If the job is nested, terminate all processes currently associated with the job and all of its child jobs in the hierarchy.
Declaration
public void Kill(int exitCode = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | exitCode | The exit code to be used by all processes and threads in the job object. |
SetLimits(JobLimits)
Sets the JobObject's limits.
Declaration
public void SetLimits(in JobLimits newLimits)
Parameters
Type | Name | Description |
---|---|---|
JobLimits | newLimits | The new limits to apply. |
SetNotifications(JobNotifications)
Sets the notifications for the JobObject.
Declaration
public void SetNotifications(in JobNotifications newNotifications)
Parameters
Type | Name | Description |
---|---|---|
JobNotifications | newNotifications | The new notifications to apply. |
Events
| Improve this Doc View SourceCpuRateLimitExceeded
Occurs when the CPU rate limit is exceeded.
Declaration
public event EventHandler<RateLimitEventArgs> CpuRateLimitExceeded
Event Type
Type | Description |
---|---|
System.EventHandler<RateLimitEventArgs> |
Idled
Occurs when all processes assigned to the job have exited.
Declaration
public event EventHandler<EventArgs> Idled
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |
IoLimitExceeded
Occurs when an I/O limit is exceeded.
Declaration
public event EventHandler<IoLimitEventArgs> IoLimitExceeded
Event Type
Type | Description |
---|---|
System.EventHandler<IoLimitEventArgs> |
MemoryLimitExceeded
Occurs when a process assigned to the job exceeds the per-process memory limit, or when the the job's memory limit is exceeded.
Declaration
public event EventHandler<MemoryLimitEventArgs> MemoryLimitExceeded
Event Type
Type | Description |
---|---|
System.EventHandler<MemoryLimitEventArgs> |
ProcessAdded
Occurs when a process is assigned to the job.
Declaration
public event EventHandler<ProcessIdEventArgs> ProcessAdded
Event Type
Type | Description |
---|---|
System.EventHandler<ProcessIdEventArgs> |
ProcessExited
Occurs when a process assigned to the job terminates.
Declaration
public event EventHandler<ProcessExitedEventArgs> ProcessExited
Event Type
Type | Description |
---|---|
System.EventHandler<ProcessExitedEventArgs> |
ProcessLimitExceeded
Occurs when the active processes limit is exceeded.
Declaration
public event EventHandler<EventArgs> ProcessLimitExceeded
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |
TimeLimitExceeded
Occurs when a process assigned to the job exceeds the per-process time limit, or when the job's time limit is exceeded.
Declaration
public event EventHandler<TimeLimitEventArgs> TimeLimitExceeded
Event Type
Type | Description |
---|---|
System.EventHandler<TimeLimitEventArgs> |