{"record":{"id":"df7e06824e6f63af","repo":"tui-cs/Terminal.Gui","slug":"cannot-change-timeout-while-mouse-is-held-down-ca","errorCode":null,"errorMessage":"Cannot change timeout while mouse is held down. Call Stop() first.","messagePattern":"Cannot change timeout while mouse is held down\\. Call Stop\\(\\) first\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/ViewBase/Mouse/MouseHoldRepeaterImpl.cs","lineNumber":61,"sourceCode":"\n    private readonly View _mouseGrabView;\n    private readonly ITimedEvents? _timedEvents;\n    private readonly IMouseGrabHandler? _mouseGrabber;\n\n    private Timeout? _timeout;\n    private Timeout? _userTimeout;\n    private bool _isDown;\n    private object? _timeoutToken;\n\n    /// <inheritdoc/>\n    public Timeout? Timeout\n    {\n        get => _userTimeout;\n        set\n        {\n            if (_isDown)\n            {\n                throw new InvalidOperationException (\"Cannot change timeout while mouse is held down. Call Stop() first.\");\n            }\n            _userTimeout = value;\n        }\n    }\n\n    /// <summary>\n    ///     The most recent mouse event arguments associated with the mouse held down action.\n    /// </summary>\n    private Mouse? _mouseEvent;\n\n    public void Start (Mouse mouse)\n    {\n        if (_isDown)\n        {\n            return;\n        }\n\n        _mouseEvent = new Mouse","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/Mouse/MouseHoldRepeaterImpl.cs#L43-L79","documentation":"This error is thrown by MouseHoldRepeaterImpl.Timeout setter when attempting to change the Timeout property while the mouse button is currently held down (_isDown is true). The MouseHoldRepeaterImpl implements mouse-hold-repeat behavior (like auto-scroll on button hold). Changing the timeout mid-repeat would cause timing inconsistencies, so the API requires calling Stop() first to release the mouse grab before reconfiguring.","triggerScenarios":"Thrown at MouseHoldRepeaterImpl.cs:61 when the Timeout setter is invoked while _isDown is true. _isDown is set true in Start(Mouse) and set false in Stop(). This means the mouse button was pressed (Start called) but not yet released (Stop not called) when code attempts to change the repeat timeout.","commonSituations":"Attempting to dynamically adjust mouse-hold-repeat speed in response to user actions while the button is held, UI event handlers that reconfigure mouse behavior mid-interaction, race conditions where timeout reconfiguration and mouse events overlap, or test code that changes timeout without simulating mouse-up.","solutions":["Call Stop() on the MouseHoldRepeaterImpl before setting Timeout, then call Start() again if needed.","Reconfigure timeouts during mouse-up / release events, not during mouse-down / hold.","If dynamic timeout adjustment is needed mid-hold, add a pause-resume mechanism rather than changing Timeout directly.","In test code, ensure proper Start/Stop sequencing before changing configuration."],"exampleFix":"// before -- changing Timeout while mouse is held throws\nrepeater.Start(mouseEvent);\nrepeater.Timeout = newTimeout; // throws if mouse still down\n\n// after -- stop before reconfiguring\nrepeater.Stop();\nrepeater.Timeout = newTimeout;\nrepeater.Start(mouseEvent);","handlingStrategy":"validation","validationCode":"// Check _isDown state before changing Timeout (if accessible)\n// Public API: call Stop() before reconfiguring\nrepeater.Stop();\nrepeater.Timeout = newTimeout;","typeGuard":null,"tryCatchPattern":"try { repeater.Timeout = newTimeout; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"mouse is held down\"))\n{ repeater.Stop(); repeater.Timeout = newTimeout; repeater.Start(mouse); }","preventionTips":["Always call Stop() before changing the Timeout property on MouseHoldRepeaterImpl.","Reconfigure timeouts during mouse-up handlers, not during mouse-down/hold.","Implement a pause-resume pattern if dynamic timeout adjustment is needed mid-hold.","In test code, ensure proper Start/Stop sequencing before changing configuration."],"tags":["mouse","input","viewbase","state","invariant"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}