GuiDispatcher
Dispatcher implementation that marshals actions to the WPF UI thread with batching and periodic execution support.
Inherits: Disposable
Implements: IDispatcher
Constructors
public GuiDispatcher()
guiDispatcher = GuiDispatcher()
Initializes a new instance of the GuiDispatcher class using the current thread dispatcher.
public GuiDispatcher(Dispatcher dispatcher)
guiDispatcher = GuiDispatcher(dispatcher)
Initializes a new instance of the GuiDispatcher class.
- dispatcher
- The UI thread dispatcher instance.
Properties
public Dispatcher Dispatcher { get; }
value = guiDispatcher.Dispatcher
Gets the UI thread dispatcher instance.
public static GuiDispatcher GlobalDispatcher { get; }
value = GuiDispatcher.GlobalDispatcher
Gets the global singleton instance of GuiDispatcher.
public TimeSpan Interval { get; set; }
value = guiDispatcher.Interval
guiDispatcher.Interval = value
Gets or sets the batch processing interval. Default is 1 ms.
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.
public int PendingActionsCount { get; }
value = guiDispatcher.PendingActionsCount
Gets the number of actions waiting to be processed.
Methods
public void AddAction(Action action)
guiDispatcher.AddAction(action)
Queues an action for execution on the UI thread.
- action
- The action to execute.
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.
public void AddSyncAction(Action action)
guiDispatcher.AddSyncAction(action)
Executes the specified action synchronously on the UI thread.
- action
- The action to execute.
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.
protected override void DisposeManaged()
guiDispatcher.DisposeManaged()
Releases managed resources.
public void FlushPendingActions()
guiDispatcher.FlushPendingActions()
Requests immediate processing of all queued actions.
public static void InitGlobalDispatcher()
GuiDispatcher.InitGlobalDispatcher()
Initializes the global dispatcher if it has not been created yet.
public IDisposable InvokePeriodically(Action action, TimeSpan interval)
result = guiDispatcher.InvokePeriodically(action, interval)
Events
public event Action<Exception> Error
guiDispatcher.Error += handler
Raised when an error occurs during execution of an action.