GuiDispatcher

Ecng.Xaml

Dispatcher implementation that marshals actions to the WPF UI thread with batching and periodic execution support.

Inherits: Disposable

Implements: IDispatcher

Constructors

GuiDispatcher
public GuiDispatcher()
guiDispatcher = GuiDispatcher()

Initializes a new instance of the GuiDispatcher class using the current thread dispatcher.

GuiDispatcher
public GuiDispatcher(Dispatcher dispatcher)
guiDispatcher = GuiDispatcher(dispatcher)

Initializes a new instance of the GuiDispatcher class.

dispatcher
The UI thread dispatcher instance.

Properties

Dispatcher
public Dispatcher Dispatcher { get; }
value = guiDispatcher.Dispatcher

Gets the UI thread dispatcher instance.

GlobalDispatcher
public static GuiDispatcher GlobalDispatcher { get; }
value = GuiDispatcher.GlobalDispatcher

Gets the global singleton instance of GuiDispatcher.

Interval
public TimeSpan Interval { get; set; }
value = guiDispatcher.Interval
guiDispatcher.Interval = value

Gets or sets the batch processing interval. Default is 1 ms.

MaxPeriodicalActionErrors
public int MaxPeriodicalActionErrors { get; set; }
value = guiDispatcher.MaxPeriodicalActionErrors
guiDispatcher.MaxPeriodicalActionErrors = value

Gets or sets the maximum number of errors allowed for a periodic action before it is removed. Use -1 to disable the limit.

PendingActionsCount
public int PendingActionsCount { get; }
value = guiDispatcher.PendingActionsCount

Gets the number of actions waiting to be processed.

Methods

AddAction
public void AddAction(Action action)
guiDispatcher.AddAction(action)

Queues an action for execution on the UI thread.

action
The action to execute.
AddPeriodicalAction
public IDisposable AddPeriodicalAction(Action action)
result = guiDispatcher.AddPeriodicalAction(action)

Adds a periodic action that will be executed on each dispatcher tick. Returns a token that can be used to remove it.

action
The action to execute.

Returns: A token that can be used to remove the action.

AddSyncAction
public void AddSyncAction(Action action)
guiDispatcher.AddSyncAction(action)

Executes the specified action synchronously on the UI thread.

action
The action to execute.
AddSyncAction``1
public T AddSyncAction<T>(Func<T> action)
result = guiDispatcher.AddSyncAction(action)

Executes the specified function synchronously on the UI thread and returns its result.

action
The function to execute.

Returns: The function result.

CheckAccess
public bool CheckAccess()
result = guiDispatcher.CheckAccess()
DisposeManaged
protected override void DisposeManaged()
guiDispatcher.DisposeManaged()

Releases managed resources.

FlushPendingActions
public void FlushPendingActions()
guiDispatcher.FlushPendingActions()

Requests immediate processing of all queued actions.

InitGlobalDispatcher
public static void InitGlobalDispatcher()
GuiDispatcher.InitGlobalDispatcher()

Initializes the global dispatcher if it has not been created yet.

InvokePeriodically
public IDisposable InvokePeriodically(Action action, TimeSpan interval)
result = guiDispatcher.InvokePeriodically(action, interval)

Events

Error
public event Action<Exception> Error
guiDispatcher.Error += handler

Raised when an error occurs during execution of an action.