Skip to main content
net8.0net9.0net10.0

.NET wrapper for Windows Job Objects

Published
Dec 2, 2025
10mo ago
Total Downloads
119.0K
118,958

Install

dotnet add package Meziantou.Framework.Win32.Jobs --version 3.5.0
ProductVersions
.NET
net10.0net8.0net9.0

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

// Security limits
job.SetSecurityLimits(JobObjectSecurityLimit.NoAdmin);

// IO Rate limits
job.SetIoLimits(new JobIoRateLimits
{
    ControlFlags = JobIoRateFlags.Enable,
    MaxBandwidth = 100,
    MaxIops = 100,
    ReservationIops = 100,
});

You can terminate all processes associated to the job:

job.Terminate();
job.Terminate(exitCode: 1);

You can also get accounting information for processes associated with the job:

var basicInfo = job.GetBasicAccountingInformation();
var basicAndIoInfo = job.GetBasicAndIoAccountingInformation();
var memoryInfo = job.GetMemoryAccountingInformation();

Additional resources

Changes from Previous Version

No structural changes between v3.4.12 and v3.5.0.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 3 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.