Created
April 17, 2018 23:04
-
-
Save ermish/5851a4e9fdbb496a9dded517c4020914 to your computer and use it in GitHub Desktop.
Fire and Forget Async Methods in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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