Remove PInvoke.Kernel32

Former-commit-id: f0c9993c6e
This commit is contained in:
Malte Rosenbjerg 2023-01-31 23:25:33 +01:00
parent 28deedc038
commit cabfb0b2db
3 changed files with 3 additions and 63 deletions

View file

@ -1,46 +0,0 @@
using System;
using System.Runtime.InteropServices;
using static PInvoke.Kernel32;
namespace FFMpegCore.Extend {
public class Job : IDisposable {
readonly SafeObjectHandle handle;
public Job() {
this.handle = CreateJobObject(IntPtr.Zero, null);
var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION {
LimitFlags = JOB_OBJECT_LIMIT_FLAGS.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
};
var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION { BasicLimitInformation = info };
int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length);
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
if (!SetInformationJobObject(this.handle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, extendedInfoPtr, (uint)length))
throw new System.ComponentModel.Win32Exception();
}
public bool AddProcess(SafeObjectHandle processHandle) {
return AssignProcessToJobObject(this.handle, processHandle);
}
#region IDisposable Members
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing) => this.Close();
public void Close() => this.handle.Close();
#endregion
}
}

View file

@ -9,12 +9,6 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.Enums; using FFMpegCore.Enums;
using FFMpegCore.Exceptions;
using FFMpegCore.Extend;
using FFMpegCore.Helpers;
using Instances;
using PInvoke;
namespace FFMpegCore namespace FFMpegCore
{ {
@ -148,13 +142,6 @@ private async Task<IProcessResult> Process(ProcessArguments processArguments, Ca
_ffMpegArguments.Pre(); _ffMpegArguments.Pre();
using var instance = (ProcessInstance)processArguments.Start(); using var instance = (ProcessInstance)processArguments.Start();
using var job = new Job();
var processHack = (Process)typeof(ProcessInstance).GetField("_process", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
.GetValue(instance);
using var instanceHandle = new Kernel32.SafeObjectHandle(processHack.Handle, ownsHandle: false);
job.AddProcess(instanceHandle);
var cancelled = false; var cancelled = false;
void OnCancelEvent(object sender, int timeout) void OnCancelEvent(object sender, int timeout)
{ {

View file

@ -17,7 +17,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Instances" Version="3.0.0" /> <PackageReference Include="Instances" Version="3.0.0" />
<PackageReference Include="PInvoke.Kernel32" Version="0.7.104" />
<PackageReference Include="System.Text.Json" Version="7.0.1" /> <PackageReference Include="System.Text.Json" Version="7.0.1" />
</ItemGroup> </ItemGroup>