babalae/better-genshin-impact · warning · OperationCanceledException

Raw Input 初始化已取消。

Error message

Raw Input 初始化已取消。

What it means

On the RawInput worker thread, after registering devices but before signaling success, the code checks the StopRequested flag; if a stop was requested concurrently it throws OperationCanceledException('Raw Input 初始化已取消。'). This prevents partially-initialized state from being reported as ready and ensures a concurrent Stop() cleanly aborts startup.

Source

Thrown at BetterGenshinImpact/Core/Monitor/RawInputMonitor.cs:237

    }

    private void RunMessageLoop(RawInputThreadContext context)
    {
        try
        {
            context.Dispatcher = Dispatcher.CurrentDispatcher;
            context.HwndSource = new HwndSource(new HwndSourceParameters("BetterGI RawInput Monitor")
            {
                ParentWindow = HwndMessage,
                WindowStyle = 0
            });
            context.HwndSource.AddHook(WindowProc);

            RegisterRawInput(context);
            context.Registered = true;
            if (Volatile.Read(ref context.StopRequested) != 0)
            {
                throw new OperationCanceledException("Raw Input 初始化已取消。");
            }

            context.InitializationSucceeded = true;
            context.Initialized.Set();

            Dispatcher.Run();
        }
        catch (Exception ex)
        {
            if (!context.InitializationSucceeded)
            {
                context.InitializationException = ex;
                context.Initialized.Set();
            }
            Logger.LogError(ex, "Raw Input 消息窗口异常终止");
        }
        finally
        {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Treat OperationCanceledException from Start as non-fatal: log at debug/trace and continue.
  2. Avoid starting and immediately stopping the monitor; debounce UI toggles.
  3. Serialize Start/Stop with a lock or a single-threaded scheduler.

Example fix

// before
monitor.Start();

// after
try
{
    monitor.Start();
}
catch (OperationCanceledException)
{
    // expected when Start races with Stop; safe to ignore
}
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    monitor.Start();
}
catch (OperationCanceledException)
{
    // Start raced with Stop; expected and safe to ignore
    logger.LogDebug("RawInput 启动被取消");
}

Prevention

When it happens

Trigger: Calling Start() then immediately Stop() before the worker finishes setup; rapid enable/disable toggling of relative-mouse monitoring; the monitor being stopped during app shutdown while a previous Start is mid-flight.

Common situations: UI toggle flipped quickly; configuration change triggering a restart; shutdown racing with a fresh start. This is often benign (expected cancellation) rather than a fault.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/486d6f0fc63838a6. Report an issue: GitHub.