Skip to content

Instantly share code, notes, and snippets.

@dylanberry
Created April 29, 2020 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanberry/e6daa5a533053c7e47ae47d3580bb1a0 to your computer and use it in GitHub Desktop.
Save dylanberry/e6daa5a533053c7e47ae47d3580bb1a0 to your computer and use it in GitHub Desktop.
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