Table of Contents

Method OnIsRunningChanging

Namespace
Terminal.Gui.ViewBase
Assembly
Terminal.Gui.dll

OnIsRunningChanging(bool, bool)

Called before IsRunningChanging event. Override to cancel state change or extract Result.

protected virtual bool OnIsRunningChanging(bool oldIsRunning, bool newIsRunning)

Parameters

oldIsRunning bool

The current value of IsRunning.

newIsRunning bool

The new value of IsRunning (true = starting, false = stopping).

Returns

bool

true to cancel; false to proceed.

Remarks

Default implementation returns false (allow change).

IMPORTANT: When newIsRunning is false (stopping), this is the ideal place to extract Result from views before the runnable is removed from the stack. At this point, all views are still alive and accessible, and subscribers can inspect the result and optionally cancel the stop.

<pre><code class="lang-csharp">protected override bool OnIsRunningChanging (bool oldIsRunning, bool newIsRunning)
{
    if (!newIsRunning)  // Stopping
    {
        // Extract result before removal from stack
        Result = _textField.Text;

        // Or check if user wants to save first
        if (HasUnsavedChanges ())
        {
            int result = MessageBox.Query ("Save?", "Save changes?", "Yes", "No", "Cancel");
            if (result == 2) return true;  // Cancel stopping
            if (result == 0) Save ();
        }
    }

    return base.OnIsRunningChanging (oldIsRunning, newIsRunning);
}</code></pre>