using System.Runtime.InteropServices; namespace XFEToolBox.Indexing.Service.Engine; /// /// Low-resource mode only around synchronous metadata/cache IO. Begin/end must stay on the same /// dedicated service thread; CPU index builders and impersonated query threads never enter it. /// internal readonly struct NtfsIoPriority : IDisposable { private readonly bool entered; public NtfsIoPriority() { entered = OperatingSystem.IsWindows() && SetThreadPriority(GetCurrentThread(), 0x10000); } public void Dispose() { if (entered) SetThreadPriority(GetCurrentThread(), 0x20000); } [DllImport("kernel32.dll")] private static extern IntPtr GetCurrentThread(); [DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetThreadPriority(IntPtr thread, int priority); }