Force Normal IO and Page Priority

More useful when run as Task but it seems to help normal
runs as well. Related to issue #487.
This commit is contained in:
Travis Nickles 2019-03-12 16:34:24 -05:00
parent 54b6b2754a
commit a7192d2fbf
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,67 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
namespace DS4Windows
{
[SuppressUnmanagedCodeSecurity]
class Util
{
public enum PROCESS_INFORMATION_CLASS : int
{
ProcessBasicInformation = 0,
ProcessQuotaLimits,
ProcessIoCounters,
ProcessVmCounters,
ProcessTimes,
ProcessBasePriority,
ProcessRaisePriority,
ProcessDebugPort,
ProcessExceptionPort,
ProcessAccessToken,
ProcessLdtInformation,
ProcessLdtSize,
ProcessDefaultHardErrorMode,
ProcessIoPortHandlers,
ProcessPooledUsageAndLimits,
ProcessWorkingSetWatch,
ProcessUserModeIOPL,
ProcessEnableAlignmentFaultFixup,
ProcessPriorityClass,
ProcessWx86Information,
ProcessHandleCount,
ProcessAffinityMask,
ProcessPriorityBoost,
ProcessDeviceMap,
ProcessSessionInformation,
ProcessForegroundInformation,
ProcessWow64Information,
ProcessImageFileName,
ProcessLUIDDeviceMapsEnabled,
ProcessBreakOnTermination,
ProcessDebugObjectHandle,
ProcessDebugFlags,
ProcessHandleTracing,
ProcessIoPriority,
ProcessExecuteFlags,
ProcessResourceManagement,
ProcessCookie,
ProcessImageInformation,
ProcessCycleTime,
ProcessPagePriority,
ProcessInstrumentationCallback,
ProcessThreadStackAllocation,
ProcessWorkingSetWatchEx,
ProcessImageFileNameWin32,
ProcessImageFileMapping,
ProcessAffinityUpdateMode,
ProcessMemoryAllocationMode,
MaxProcessInfoClass
}
[DllImport("ntdll.dll", SetLastError = true)]
public static extern int NtSetInformationProcess(IntPtr processHandle,
PROCESS_INFORMATION_CLASS processInformationClass, ref IntPtr processInformation, uint processInformationLength);
}
}

View File

@ -141,6 +141,7 @@
<Compile Include="DS4Control\ScpDevice.cs" />
<Compile Include="DS4Control\ScpUtil.cs" />
<Compile Include="DS4Control\UdpServer.cs" />
<Compile Include="DS4Control\Util.cs" />
<Compile Include="DS4Control\X360Device.cs" />
<Compile Include="DS4Forms\LanguagePackComboBox.cs">
<SubType>UserControl</SubType>

View File

@ -75,6 +75,16 @@ namespace DS4Windows
}
catch { } // Ignore problems raising the priority.
// Force Normal IO Priority
IntPtr ioPrio = new IntPtr(2);
Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle,
Util.PROCESS_INFORMATION_CLASS.ProcessIoPriority, ref ioPrio, 4);
// Force Normal Page Priority
IntPtr pagePrio = new IntPtr(5);
Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle,
Util.PROCESS_INFORMATION_CLASS.ProcessPagePriority, ref pagePrio, 4);
try
{
// another instance is already running if OpenExsting succeeds.