Skip to content

Instantly share code, notes, and snippets.

@ermish
Created April 17, 2018 23:04
Show Gist options
  • Save ermish/5851a4e9fdbb496a9dded517c4020914 to your computer and use it in GitHub Desktop.
Save ermish/5851a4e9fdbb496a9dded517c4020914 to your computer and use it in GitHub Desktop.
Fire and Forget Async Methods in C#
public static async void FireAndForget<T>(this Task task, ILogger<T> logger)
{
try
{
await task;
}
catch (Exception e)
{
logger.LogError(e, $"An exception occured during the fire and forget task: {e.GetBaseException()}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment