Meziantou.Framework.Win32.Jobs 3.2.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Meziantou.Framework.Win32.Jobs --version 3.2.1
NuGet\Install-Package Meziantou.Framework.Win32.Jobs -Version 3.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Meziantou.Framework.Win32.Jobs" Version="3.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Meziantou.Framework.Win32.Jobs --version 3.2.1
#r "nuget: Meziantou.Framework.Win32.Jobs, 3.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Meziantou.Framework.Win32.Jobs as a Cake Addin
#addin nuget:?package=Meziantou.Framework.Win32.Jobs&version=3.2.1

// Install Meziantou.Framework.Win32.Jobs as a Cake Tool
#tool nuget:?package=Meziantou.Framework.Win32.Jobs&version=3.2.1

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);

Additional resources

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Meziantou.Framework.Win32.Jobs:

Package Downloads
MongoDBInstance5_0

Package Description

MongoDBInstance3_4

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.2.1 1,997 11/15/2023
3.2.0 1,767 11/23/2022
3.1.1 280 11/22/2022
3.1.0 287 11/19/2022
3.0.0 294 11/18/2022
2.0.2 891 7/14/2021
2.0.1 320 4/22/2021
2.0.0 385 9/24/2020
1.0.4 467 6/25/2020
1.0.3 482 10/23/2019
1.0.2 554 4/10/2019
1.0.1 876 10/21/2018
1.0.0 845 4/11/2018