Table of Contents

Method Run

Namespace
Terminal.Gui
Assembly
Terminal.Gui.dll

Run(Func<Exception, bool>?, IConsoleDriver?)

Runs the application by creating a Toplevel object and calling Run(Toplevel, Func<Exception, bool>?).

public static Toplevel Run(Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null)

Parameters

errorHandler Func<Exception, bool>
driver IConsoleDriver

Returns

Toplevel

The created Toplevel object. The caller is responsible for disposing this object.

Remarks

Calling Init(IConsoleDriver?, string?) first is not needed as this function will initialize the application.

Shutdown() must be called when the application is closing (typically after Run> has returned) to ensure resources are cleaned up and terminal settings restored.

The caller is responsible for disposing the object returned by this method.

Run<T>(Func<Exception, bool>?, IConsoleDriver?)

Runs the application by creating a Toplevel-derived object of type T and calling Run(Toplevel, Func<Exception, bool>?).

public static T Run<T>(Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null) where T : Toplevel, new()

Parameters

errorHandler Func<Exception, bool>
driver IConsoleDriver

The IConsoleDriver to use. If not specified the default driver for the platform will be used ( Terminal.Gui.WindowsDriver, Terminal.Gui.CursesDriver, or Terminal.Gui.NetDriver). Must be null if Init(IConsoleDriver?, string?) has already been called.

Returns

T

The created T object. The caller is responsible for disposing this object.

Type Parameters

T

Remarks

Calling Init(IConsoleDriver?, string?) first is not needed as this function will initialize the application.

Shutdown() must be called when the application is closing (typically after Run> has returned) to ensure resources are cleaned up and terminal settings restored.

The caller is responsible for disposing the object returned by this method.

Run(Toplevel, Func<Exception, bool>?)

Runs the Application using the provided Toplevel view.

public static void Run(Toplevel view, Func<Exception, bool>? errorHandler = null)

Parameters

view Toplevel

The Toplevel to run as a modal.

errorHandler Func<Exception, bool>

RELEASE builds only: Handler for any unhandled exceptions (resumes when returns true, rethrows when null).

Remarks

This method is used to start processing events for the main application, but it is also used to run other modal Views such as Dialog boxes.

To make a Run(Toplevel, Func<Exception, bool>?) stop execution, call RequestStop(Toplevel?).

Calling Run(Toplevel, Func<Exception, bool>?) is equivalent to calling Begin(Toplevel), followed by RunLoop(RunState), and then calling End(RunState).

Alternatively, to have a program control the main loop and process events manually, call Begin(Toplevel) to set things up manually and then repeatedly call RunLoop(RunState) with the wait parameter set to false. By doing this the RunLoop(RunState) method will only process any pending events, timers, idle handlers and then return control immediately.

When using Run<T>(Func<Exception, bool>?, IConsoleDriver?) or Run(Func<Exception, bool>?, IConsoleDriver?)Init(IConsoleDriver?, string?) will be called automatically.

RELEASE builds only: When errorHandler is null any exceptions will be rethrown. Otherwise, if errorHandler will be called. If errorHandler returns true the RunLoop(RunState) will resume; otherwise this method will exit.