Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static class TaskUtilities
{
#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void
public static async void FireAndForgetSafeAsync(this Task task, Action<Exception> handleErrorAction = null)
#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void
{
try
{
await task.ConfigureAwait(true);
}
catch (Exception ex)
{
handleErrorAction?.Invoke(ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment