Table of Contents

Class UIThreadHelper

Namespace
VisioForge.Core.Helpers
Assembly
VisioForge.Core.dll

Provides helper methods for executing code on the UI thread in cross-platform applications. Automatically detects and captures the UI thread context for WPF, WinForms, and MAUI applications.

public static class UIThreadHelper

Inheritance

Inherited Members

Properties

IsUIThread

Gets a value indicating whether the current thread is the UI thread.

public static bool IsUIThread { get; }

Property Value

bool

Methods

RunOnUIThread(Action)

Executes the specified action on the UI thread.

public static void RunOnUIThread(Action action)

Parameters

action Action

The action to execute on the UI thread.

Remarks

If already on the UI thread, the action is executed immediately. Otherwise, the action is posted to the UI thread's synchronization context. If no UI context is available, the action runs on the current thread as a fallback.

RunOnUIThreadAsync(Action)

Executes the specified action on the UI thread asynchronously.

public static Task RunOnUIThreadAsync(Action action)

Parameters

action Action

The action to execute on the UI thread.

Returns

Task

A task that represents the asynchronous operation.

Remarks

This method returns a Task that completes when the action has been executed. If the action throws an exception, it will be propagated through the returned Task.

RunOnUIThreadAsync<T>(Func<T>)

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

public static Task<T> RunOnUIThreadAsync<T>(Func<T> function)

Parameters

function Func<T>

The function to execute on the UI thread.

Returns

Task<T>

A task that represents the asynchronous operation and contains the function's result.

Type Parameters

T

The type of the result returned by the function.

Remarks

This method returns a Task that completes when the function has been executed. If the function throws an exception, it will be propagated through the returned Task.