Skip to content

Commit

Permalink
重命名Job至ProcessTerminator
Browse files Browse the repository at this point in the history
  • Loading branch information
Rcmcpe committed Nov 12, 2020
1 parent 25389fd commit e07e50a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Auto Arknights Core/Adb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public Adb(string executable, string targetSerial)
if (Process.GetProcessesByName("adb").Any()) return;
ExecuteCore("start-server", out _);

var job = new Job();
job.AddProcess(Process.GetProcessesByName("adb")[0].Handle);
var job = new ProcessTerminator();
job.Track(Process.GetProcessesByName("adb")[0]);
}

public string Executable { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;

// ReSharper disable FieldCanBeMadeReadOnly.Global
Expand All @@ -9,13 +10,13 @@ namespace REVUnit.AutoArknights.Core
/// <summary>
/// 用来关闭ADB的黑科技。
/// </summary>
public class Job
public class ProcessTerminator
{
private readonly IntPtr _handle;

public Job()
public ProcessTerminator()
{
_handle = CreateJobObject(IntPtr.Zero, Guid.NewGuid().ToString());
_handle = CreateJobObject(IntPtr.Zero, $"AutoArknights ADB Tracker {Environment.ProcessId}");

var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION { LimitFlags = 0x2000 };
var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION { BasicLimitInformation = info };
Expand All @@ -36,9 +37,9 @@ public Job()
}
}

public void AddProcess(IntPtr handle)
public void Track(Process process)
{
AssignProcessToJobObject(_handle, handle);
AssignProcessToJobObject(_handle, process.Handle);
}

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
Expand Down

0 comments on commit e07e50a

Please sign in to comment.