Table of Contents

Method OnIsRunningChanging

Namespace
Terminal.Gui.Views
Assembly
Terminal.Gui.dll

OnIsRunningChanging(bool, bool)

Called before IsRunningChanging event. Override to cancel state change or perform cleanup.

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 perform cleanup or validation before the runnable is removed from the stack.

<pre><code class="lang-csharp">protected override bool OnIsRunningChanging (bool oldIsRunning, bool newIsRunning)
{
    if (!newIsRunning)  // Stopping
    {
        // Check if user wants to save first
        if (HasUnsavedChanges ())
        {
            int result = MessageBox.Query (App, "Save?", "Save changes?", "Yes", "No", "Cancel");
            if (result == 2) return true;  // Cancel stopping
            if (result == 0) Save ();
        }
    }

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