Show / Hide Table of Contents

Class TaskHelper

Inheritance
object
TaskHelper
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Threading
Assembly: SoCore.dll
Syntax
public static class TaskHelper

Methods

RunInUserContext(Action, CancellationToken)

Perform a Task.Run while ensuring that NetServer's contexts is taken care of and disposed request scoped instances are not used.

Declaration
public static Task RunInUserContext(Action action, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Action action
CancellationToken cancellationToken
Returns
Type Description
Task

Task that is safe not to await for.

Remarks

Execute the work in a task. This task supports that it starts in the context of a request, or other operation, where the scope is disposed before the task is completed. Information about the logged in user is handled as well.

RunInUserContext(Func<CancellationToken, Task>, CancellationToken)

Perform a Task.Run while ensuring that NetServer's contexts is taken care of and disposed request scoped instances are not used.

Declaration
public static Task RunInUserContext(Func<CancellationToken, Task> action, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Func<CancellationToken, Task> action
CancellationToken cancellationToken
Returns
Type Description
Task

Task that is safe not to await for.

Remarks

Execute the work in a task. This task supports that it starts in the context of a request, or other operation, where the scope is disposed before the task is completed. Information about the logged in user is handled as well.

RunInUserContext(Func<Task>, CancellationToken)

Perform a Task.Run while ensuring that NetServer's contexts is taken care of and disposed request scoped instances are not used.

Declaration
public static Task RunInUserContext(Func<Task> action, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Func<Task> action
CancellationToken cancellationToken
Returns
Type Description
Task

Task that is safe not to await for.

Remarks

Execute the work in a task. This task supports that it starts in the context of a request, or other operation, where the scope is disposed before the task is completed. Information about the logged in user is handled as well.

WaitAsync(Task, CancellationToken)

Alternative to System.Threading.Tasks.Task.WaitAsync which is only available on NET5+, attach this to a task that might not have a cancellation token https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.whenany?view=net-8.0

Declaration
public static Task WaitAsync(this Task task, CancellationToken cancellationToken)
Parameters
Type Name Description
Task task
CancellationToken cancellationToken
Returns
Type Description
Task

WaitForAllRunningTasksAsync(CancellationToken)

Wait for all currently running tasks to comlete

Declaration
public static Task WaitForAllRunningTasksAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken
Returns
Type Description
Task
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top