Install
dotnet add package Meziantou.Framework.Win32.Jobs --version 3.1.1
| Product | Versions |
|---|---|
| .NET |
README
Meziantou.Framework.Win32.Jobs
Meziantou.Framework.Win32.Jobs is a wrapper for Job Objects. A job object allows groups of processes to be managed as a unit. Operations performed on a job object affect all processes associated with the job object. Examples include enforcing limits such as working set size and process priority or terminating all processes associated with a job.
// Create the Job object and assign it to the current process
using var job = new JobObject();
job.SetLimits(new JobObjectLimits()
{
Flags = JobObjectLimitFlags.DieOnUnhandledException |
JobObjectLimitFlags.KillOnJobClose,
});
job.AssignProcess(Process.GetCurrentProcess());
// Start a child process. This process will be terminated if the current process exits
// as the job has the flag KillOnJobClose.
var process = Process.Start("child");
process.WaitForExit();
You can also set limits to the Job Object:
job.SetLimits(new JobObjectLimits()
{
PerProcessUserTimeLimit = ...,
PerJobUserTimeLimit = ...,
MinimumWorkingSetSize = ...,
MaximumWorkingSetSize = ...,
ProcessMemoryLimit = ...,
JobMemoryLimit = ...,
ActiveProcessLimit = ...,
});
// Restrict UI features
job.SetUIRestrictions(Natives.JobObjectUILimit.ReadClipboard);
// Limit CPU
job.SetCpuRateHardCap(2000); // 20% of the CPU
job.SetCpuRate(1000, 3000); // 10% to 30% of the CPU
job.SetCpuRateWeight(5); // 1 to 9
// Network limits
job.SetNetRateLimits(10000); // 10Kb/s
You can terminate all processes associated to the job:
job.Terminate();
job.Terminate(exitCode: 1);
Additional resources
Changes from Previous Version
No structural changes between v3.1.0 and v3.1.1.
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.