Class AsyncHelper
A set of helper functions for waiting on tasks and running them synchronously
This should be used sparingly and only in areas that require it like validation attributes, as this can lock up the UI
Used mostly within single threaded enviromnents such as a command console
Inherited Members
Namespace: LemonEdge.Utils
Assembly: LemonEdge.Utils.dll
Syntax
public static class AsyncHelper
Properties
HasSynchronizationContext
Indicates the UI has a SynchronizationContext. We need to ensure tasks return on the same UI thread when being run Synchronisaly
Declaration
public static bool HasSynchronizationContext { get; set; }
Property Value
Type | Description |
---|---|
bool |
StandardWaitingAction
This defines a standard acton to repeat every second while waiting on a task This is only required in singlethreaded enviroments such as a command console to provide an indication of progress
Declaration
public static Action StandardWaitingAction { get; set; }
Property Value
Type | Description |
---|---|
Action |
Methods
WaitOnTask(Func<Task>)
Run the specified task synchronously.
Will run on a seperate synchronisation context and come back to this synchronisation context for resumption
Declaration
public static void WaitOnTask(this Func<Task> task)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | task | The task to run synchronously |
WaitOnTaskWithStandard(Func<Task>)
Run the specified task synchronously, and if any standard wait action is active will run that every second while it waits
If not standard action is active then Will run on a seperate synchronisation context and come back to this synchronisation context for resumption
Declaration
public static void WaitOnTaskWithStandard(this Func<Task> task)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | task | The task to run synchronously |
WaitOnTaskWithStandard<T>(Func<Task<T>>)
Run the specified task synchronously.
Will run on a seperate synchronisation context and come back to this synchronisation context for resumption
Declaration
public static T WaitOnTaskWithStandard<T>(this Func<Task<T>> task)
Parameters
Type | Name | Description |
---|---|---|
Func<Task<T>> | task | The task to run synchronously |
Returns
Type | Description |
---|---|
T | The result of the waited task |
Type Parameters
Name | Description |
---|---|
T |
WaitOnTask<T>(Func<Task<T>>)
Run the specified task synchronously.
Will run on a seperate synchronisation context and come back to this synchronisation context for resumption
Declaration
public static T WaitOnTask<T>(this Func<Task<T>> task)
Parameters
Type | Name | Description |
---|---|---|
Func<Task<T>> | task | The task to run synchronously |
Returns
Type | Description |
---|---|
T | The result of the waited task |
Type Parameters
Name | Description |
---|---|
T |