Meziantou.Framework.Win32.Jobs 3.4.2

Prefix Reserved
dotnet add package Meziantou.Framework.Win32.Jobs --version 3.4.2                
NuGet\Install-Package Meziantou.Framework.Win32.Jobs -Version 3.4.2                
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.4.2" />                
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.4.2                
#r "nuget: Meziantou.Framework.Win32.Jobs, 3.4.2"                
#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.4.2

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

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 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.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (3)

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

Package Downloads
MongoDBInstance5_0

Package Description

MongoDBInstance3_4

Package Description

Raccoon.Tools.WindowsJob

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Meziantou.Framework.Win32.Jobs:

Repository Stars
Flow-Launcher/Flow.Launcher
:mag: Quick file search & app launcher for Windows with community-made plugins
Version Downloads Last updated
3.4.2 56 11/22/2024
3.4.1 144 11/17/2024
3.4.0 2,501 6/11/2024
3.3.0 210 5/31/2024
3.2.1 3,344 11/15/2023
3.2.0 1,879 11/23/2022
3.1.1 310 11/22/2022
3.1.0 321 11/19/2022
3.0.0 311 11/18/2022
2.0.2 947 7/14/2021
2.0.1 348 4/22/2021
2.0.0 414 9/24/2020
1.0.4 549 6/25/2020
1.0.3 515 10/23/2019
1.0.2 579 4/10/2019
1.0.1 925 10/21/2018
1.0.0 883 4/11/2018