Table of Contents

Class HostedSession

Namespace
SharpConsoleUI
Assembly
SharpConsoleUI.dll

A running console window system whose frames the caller drives, returned by BeginHosted().

public sealed class HostedSession : IDisposable
Inheritance
HostedSession
Implements
Inherited Members
Extension Methods

Remarks

Run() owns its loop and blocks the calling thread. A host that already has an event loop — a browser, a game loop, a GUI application embedding a console surface — uses this instead and calls Tick() once per frame.

Disposing the session performs the same teardown Run() does on exit, so the terminal (or host) is restored even if the loop throws. The using form makes that structural:

using var session = ws.BeginHosted();
while (session.Tick())
{
    // Pump the host's own work here — its message queue, its render callback.
}

Do not add a sleep of your own. Each Tick() ends with the system's own adaptive idle wait, which shortens when there is work and lengthens when there is not. A host that must not block inside Tick() — a browser frame callback, a game loop — sets BlockWhenIdle to false and paces the calls with its own scheduler instead.

Not thread-safe, and deliberately so: call Tick() on the same thread that called BeginHosted(), which is captured as the UI thread.

Methods

Dispose()

Stops the system and restores what BeginHosted() established. Safe to call more than once.

public void Dispose()

Tick()

Runs one iteration of the main loop: input, queued UI actions, animation advance, render when dirty, then the idle wait (see BlockWhenIdle).

public bool Tick()

Returns

bool

true while the system is running; false once it should stop.

Remarks

Exceptions propagate to the caller, which owns its own error policy — unlike Run(), which catches them and sets an exit code.