Class GuiDispatcher
Dispatcher implementation that marshals actions to the WPF UI thread with batching and periodic execution support.
public class GuiDispatcher : Disposable, IDisposable, IDispatcher
- Inheritance
-
GuiDispatcher
- Implements
- Inherited Members
- Extension Methods
Constructors
GuiDispatcher()
Initializes a new instance of the GuiDispatcher class using the current thread dispatcher.
public GuiDispatcher()
GuiDispatcher(Dispatcher)
Initializes a new instance of the GuiDispatcher class.
public GuiDispatcher(Dispatcher dispatcher)
Parameters
dispatcher
DispatcherThe UI thread dispatcher instance.
Properties
Dispatcher
Gets the UI thread dispatcher instance.
public Dispatcher Dispatcher { get; }
Property Value
GlobalDispatcher
Gets the global singleton instance of GuiDispatcher.
public static GuiDispatcher GlobalDispatcher { get; }
Property Value
Interval
Gets or sets the batch processing interval. Default is 1 ms.
public TimeSpan Interval { get; set; }
Property Value
MaxPeriodicalActionErrors
Gets or sets the maximum number of errors allowed for a periodic action before it is removed. Use -1 to disable the limit.
public int MaxPeriodicalActionErrors { get; set; }
Property Value
PendingActionsCount
Gets the number of actions waiting to be processed.
public int PendingActionsCount { get; }
Property Value
Methods
AddAction(Action)
Queues an action for execution on the UI thread.
public void AddAction(Action action)
Parameters
action
ActionThe action to execute.
AddPeriodicalAction(Action)
Adds a periodic action that will be executed on each dispatcher tick. Returns a token that can be used to remove it.
public object AddPeriodicalAction(Action action)
Parameters
action
ActionThe action to execute.
Returns
- object
A token that can be used to remove the action.
AddSyncAction(Action)
Executes the specified action synchronously on the UI thread.
public void AddSyncAction(Action action)
Parameters
action
ActionThe action to execute.
AddSyncAction<T>(Func<T>)
Executes the specified function synchronously on the UI thread and returns its result.
public T AddSyncAction<T>(Func<T> action)
Parameters
action
Func<T>The function to execute.
Returns
- T
The function result.
Type Parameters
T
The return type.
CheckAccess()
Verify that current thread is dispatcher thread.
public bool CheckAccess()
Returns
- bool
Operation result.
DisposeManaged()
Releases managed resources.
protected override void DisposeManaged()
FlushPendingActions()
Requests immediate processing of all queued actions.
public void FlushPendingActions()
InitGlobalDispatcher()
Initializes the global dispatcher if it has not been created yet.
public static void InitGlobalDispatcher()
RemovePeriodicalAction(object)
Removes a previously added periodic action.
public void RemovePeriodicalAction(object token)
Parameters
token
objectThe token returned by AddPeriodicalAction(Action).
Events
Error
Raised when an error occurs during execution of an action.
public event Action<Exception> Error