XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEToolBox

【WPF】XFE工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Runtime.InteropServices;

namespace XFEToolBox.Indexing.Service.Engine;

/// <summary>
/// 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.
/// </summary>
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);
}