File size: 898 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#nullable enable

using System.Runtime.InteropServices;

internal static partial class Interop
{
    internal static partial class Windows
    {
        internal sealed class SafeJobHandle : SafeHandle
        {
            public SafeJobHandle() : base(invalidHandleValue: nint.Zero, ownsHandle: true) { }

            public override bool IsInvalid => handle == nint.Zero;

            protected override bool ReleaseHandle()
                => Windows.CloseHandle(handle);
        }

        [LibraryImport("kernel32.dll", EntryPoint = "CreateJobObjectW", SetLastError = true)]
        private static partial SafeJobHandle CreateJobObject(
            nint lpJobAttributes,
            nint lpName);

        internal static SafeJobHandle CreateJobObject()
            => CreateJobObject(nint.Zero, nint.Zero);
    }
}