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()

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

GuiDispatcher(Dispatcher)

Initializes a new instance of the GuiDispatcher class.

dispatcher
The UI thread dispatcher instance.

Properties

Dispatcher : Dispatcher

Gets the UI thread dispatcher instance.

GlobalDispatcher : GuiDispatcher

Gets the global singleton instance of GuiDispatcher.

Interval : TimeSpan

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

MaxPeriodicalActionErrors : int

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

PendingActionsCount : int

Gets the number of actions waiting to be processed.

Methods

AddAction(Action)

Queues an action for execution on the UI thread.

action
The action to execute.
AddPeriodicalAction(Action) : IDisposable

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(Action) : T

Executes the specified action synchronously on the UI thread.

action
The action to execute.
AddSyncAction``1(Func<T>)

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

action
The function to execute.

Returns: The function result.

DisposeManaged()

Releases managed resources.

FlushPendingActions()

Requests immediate processing of all queued actions.

InitGlobalDispatcher()

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

Events

Error : Action<Exception>

Raised when an error occurs during execution of an action.