Class SafeFireAndForgetExtensions
Extension methods for System.Threading.Tasks.Task and System.Threading.Tasks.ValueTask
Inheritance
Namespace: ISynergy.Framework.Core.Extensions
Assembly: ISynergy.Framework.Core.dll
Syntax
public static class SafeFireAndForgetExtensions : object
Methods
View SourceInitialize(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 |
RemoveDefaultExceptionHandling()
Remove the default action for SafeFireAndForget
Declaration
public static void RemoveDefaultExceptionHandling()
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, |
System.Boolean | continueOnCapturedContext | If set to |
Returns
Type | Description |
---|---|
Task |
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, |
System.Boolean | continueOnCapturedContext | If set to |
Returns
Type | Description |
---|---|
Task |
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, |
System.Boolean | continueOnCapturedContext | If set to |
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 |
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, |
System.Boolean | continueOnCapturedContext | If set to |
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 |
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, |