Generated by DocFX

Class SafeFireAndForgetExtensions

Extension methods for System.Threading.Tasks.Task and System.Threading.Tasks.ValueTask

Inheritance
System.Object
SafeFireAndForgetExtensions
Namespace: ISynergy.Framework.Core.Extensions
Assembly: ISynergy.Framework.Core.dll
Syntax
public static class SafeFireAndForgetExtensions : object

Methods

View Source

Initialize(in Boolean)

LoadAssembly SafeFireAndForget

Warning: When true, there is no way to catch this exception and it will always result in a crash. Recommended only for debugging purposes.

Declaration
public static void Initialize(in bool shouldAlwaysRethrowException = false)
Parameters
Type Name Description
System.Boolean shouldAlwaysRethrowException

If set to true, after the exception has been caught and handled, the exception will always be rethrown.

View Source

RemoveDefaultExceptionHandling()

Remove the default action for SafeFireAndForget

Declaration
public static void RemoveDefaultExceptionHandling()
View Source

SafeFireAndForget(Task, in Nullable<Action<Exception>>, in Boolean)

Safely execute the Task without waiting for it to complete before moving to the next line of code; commonly known as "Fire And Forget". Inspired by John Thiriet's blog post, "Removing Async Void": https://johnthiriet.com/removing-async-void/.

Declaration
public static Task SafeFireAndForget(this Task task, in Action<Exception>? onException = null, in bool continueOnCapturedContext = false)
Parameters
Type Name Description
Task task

Task.

System.Nullable<Action<Exception>> onException

If an exception is thrown in the Task, onException will execute. If onException is null, the exception will be re-thrown

System.Boolean continueOnCapturedContext

If set to true, continue on captured context; this will ensure that the Synchronization Context returns to the calling thread. If set to false, continue on a different context; this will allow the Synchronization Context to continue on a different thread

Returns
Type Description
Task
View Source

SafeFireAndForget(ValueTask, in Nullable<Action<Exception>>, in Boolean)

Safely execute the ValueTask without waiting for it to complete before moving to the next line of code; commonly known as "Fire And Forget". Inspired by John Thiriet's blog post, "Removing Async Void": https://johnthiriet.com/removing-async-void/.

Declaration
public static Task SafeFireAndForget(this ValueTask task, in Action<Exception>? onException = null, in bool continueOnCapturedContext = false)
Parameters
Type Name Description
ValueTask task

ValueTask.

System.Nullable<Action<Exception>> onException

If an exception is thrown in the ValueTask, onException will execute. If onException is null, the exception will be re-thrown

System.Boolean continueOnCapturedContext

If set to true, continue on captured context; this will ensure that the Synchronization Context returns to the calling thread. If set to false, continue on a different context; this will allow the Synchronization Context to continue on a different thread

Returns
Type Description
Task
View Source

SafeFireAndForget<TException>(Task, in Nullable<Action<TException>>, in Boolean)

Safely execute the Task without waiting for it to complete before moving to the next line of code; commonly known as "Fire And Forget". Inspired by John Thiriet's blog post, "Removing Async Void": https://johnthiriet.com/removing-async-void/.

Declaration
public static Task SafeFireAndForget<TException>(this Task task, in Action<TException>? onException = null, in bool continueOnCapturedContext = false)
    where TException : Exception
Parameters
Type Name Description
Task task

Task.

System.Nullable<Action<TException>> onException

If an exception is thrown in the Task, onException will execute. If onException is null, the exception will be re-thrown

System.Boolean continueOnCapturedContext

If set to true, continue on captured context; this will ensure that the Synchronization Context returns to the calling thread. If set to false, continue on a different context; this will allow the Synchronization Context to continue on a different thread

Returns
Type Description
Task
Type Parameters
Name Description
TException

Exception type. If an exception is thrown of a different type, it will not be handled

View Source

SafeFireAndForget<TException>(ValueTask, in Nullable<Action<TException>>, in Boolean)

Safely execute the ValueTask without waiting for it to complete before moving to the next line of code; commonly known as "Fire And Forget". Inspired by John Thiriet's blog post, "Removing Async Void": https://johnthiriet.com/removing-async-void/.

Declaration
public static Task SafeFireAndForget<TException>(this ValueTask task, in Action<TException>? onException = null, in bool continueOnCapturedContext = false)
    where TException : Exception
Parameters
Type Name Description
ValueTask task

ValueTask.

System.Nullable<Action<TException>> onException

If an exception is thrown in the Task, onException will execute. If onException is null, the exception will be re-thrown

System.Boolean continueOnCapturedContext

If set to true, continue on captured context; this will ensure that the Synchronization Context returns to the calling thread. If set to false, continue on a different context; this will allow the Synchronization Context to continue on a different thread

Returns
Type Description
Task
Type Parameters
Name Description
TException

Exception type. If an exception is thrown of a different type, it will not be handled

View Source

SetDefaultExceptionHandling(in Action<Exception>)

Set the default action for SafeFireAndForget to handle every exception

Declaration
public static void SetDefaultExceptionHandling(in Action<Exception> onException)
Parameters
Type Name Description
Action<Exception> onException

If an exception is thrown in the Task using SafeFireAndForget, onException will execute