Search Results for

    Show / Hide Table of Contents

    Class MainLoop

    Simple main loop implementation that can be used to monitor file descriptor, run timers and idle handlers.
    Inheritance
    object
    MainLoop
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Terminal.Gui
    Assembly: Terminal.Gui.dll
    Syntax
    public class MainLoop
    Remarks
    Monitoring of file descriptors is only available on Unix, there does not seem to be a way of supporting this on Windows.

    Constructors

    | Edit this page View Source

    MainLoop(IMainLoopDriver)

    Creates a new Mainloop.
    Declaration
    public MainLoop(IMainLoopDriver driver)
    Parameters
    Type Name Description
    IMainLoopDriver driver Should match the ConsoleDriver (one of the implementations FakeMainLoop, UnixMainLoop, NetMainLoop or WindowsMainLoop).

    Properties

    | Edit this page View Source

    Driver

    The current IMainLoopDriver in use.
    Declaration
    public IMainLoopDriver Driver { get; }
    Property Value
    Type Description
    IMainLoopDriver The driver.
    | Edit this page View Source

    IdleHandlers

    Gets a copy of the list of all idle handlers.
    Declaration
    public ReadOnlyCollection<Func<bool>> IdleHandlers { get; }
    Property Value
    Type Description
    ReadOnlyCollection<Func<bool>>
    | Edit this page View Source

    Timeouts

    Gets the list of all timeouts sorted by the TimeSpan time ticks./>. A shorter limit time can be added at the end, but it will be called before an earlier addition that has a longer limit time.
    Declaration
    public SortedList<long, MainLoop.Timeout> Timeouts { get; }
    Property Value
    Type Description
    SortedList<long, MainLoop.Timeout>

    Methods

    | Edit this page View Source

    AddIdle(Func<bool>)

    Adds specified idle handler function to mainloop processing. The handler function will be called once per iteration of the main loop after other events have been handled.
    Declaration
    public Func<bool> AddIdle(Func<bool> idleHandler)
    Parameters
    Type Name Description
    Func<bool> idleHandler Token that can be used to remove the idle handler with RemoveIdle(Func<bool>) .
    Returns
    Type Description
    Func<bool>
    Remarks

    Remove an idle hander by calling RemoveIdle(Func<bool>) with the token this method returns.

    If the idleHandler returns false it will be removed and not called subsequently.

    | Edit this page View Source

    AddTimeout(TimeSpan, Func<MainLoop, bool>)

    Adds a timeout to the mainloop.
    Declaration
    public object AddTimeout(TimeSpan time, Func<MainLoop, bool> callback)
    Parameters
    Type Name Description
    TimeSpan time
    Func<MainLoop, bool> callback
    Returns
    Type Description
    object
    Remarks
    When time specified passes, the callback will be invoked. If the callback returns true, the timeout will be reset, repeating the invocation. If it returns false, the timeout will stop and be removed. The returned value is a token that can be used to stop the timeout by calling RemoveTimeout(object).
    | Edit this page View Source

    EventsPending(bool)

    Determines whether there are pending events to be processed.
    Declaration
    public bool EventsPending(bool wait = false)
    Parameters
    Type Name Description
    bool wait
    Returns
    Type Description
    bool
    Remarks
    You can use this method if you want to probe if events are pending. Typically used if you need to flush the input queue while still running some of your own code in your main thread.
    | Edit this page View Source

    Invoke(Action)

    Runs action on the thread that is processing events
    Declaration
    public void Invoke(Action action)
    Parameters
    Type Name Description
    Action action the action to be invoked on the main processing thread.
    | Edit this page View Source

    MainIteration()

    Runs one iteration of timers and file watches
    Declaration
    public void MainIteration()
    Remarks
    You use this to process all pending events (timers, idle handlers and file watches). You can use it like this: while (main.EvensPending ()) MainIteration ();
    | Edit this page View Source

    RemoveIdle(Func<bool>)

    Removes an idle handler added with AddIdle(Func<bool>) from processing.
    Declaration
    public bool RemoveIdle(Func<bool> token)
    Parameters
    Type Name Description
    Func<bool> token A token returned by AddIdle(Func<bool>)
    Returns
    Type Description
    bool
    | Edit this page View Source

    RemoveTimeout(object)

    Removes a previously scheduled timeout
    Declaration
    public bool RemoveTimeout(object token)
    Parameters
    Type Name Description
    object token
    Returns
    Type Description
    bool
    Remarks
    The token parameter is the value returned by AddTimeout.
    | Edit this page View Source

    Run()

    Runs the mainloop.
    Declaration
    public void Run()
    | Edit this page View Source

    Stop()

    Stops the mainloop.
    Declaration
    public void Stop()

    Events

    | Edit this page View Source

    TimeoutAdded

    Invoked when a new timeout is added. To be used in the case when ExitRunLoopAfterFirstIteration is true.
    Declaration
    public event Action<long> TimeoutAdded
    Event Type
    Type Description
    Action<long>
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX