Interface IMainThreadDispatcher
Determines whether method invocations require main-thread execution and dispatches them accordingly. Implementations encapsulate runtime-specific thread-affinity rules (e.g. Unity API calls that must run on the main thread).
Namespace: Serenity.Tasking.Application.Interfaces
Assembly: Serenity.Global.Application.dll
Syntax
public interface IMainThreadDispatcher
Properties
IsAvailable
Gets whether the dispatcher is available and operational.
Declaration
bool IsAvailable { get; }
Property Value
| Type | Description |
|---|---|
| bool | True if main-thread dispatch is available in this runtime. |
Methods
InvokeOnMainThreadAsync(Func<Task>)
Executes the action on the main thread and awaits its completion. If already on the main thread, executes directly.
Declaration
Task InvokeOnMainThreadAsync(Func<Task> action)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task> | action | The async action to execute. |
Returns
| Type | Description |
|---|---|
| Task | A task representing completion of the dispatched action. |
RequiresMainThread(MethodInfo, Type)
Determines whether the given method on the given type requires execution on the main thread.
Declaration
bool RequiresMainThread(MethodInfo method, Type targetType)
Parameters
| Type | Name | Description |
|---|---|---|
| MethodInfo | method | The method to inspect. |
| Type | targetType | The type that declares or owns the method. |
Returns
| Type | Description |
|---|---|
| bool | True if the call must be dispatched to the main thread. |