I'm trying to call an async method (in an ASP.NET Web API 2 app) without awaiting for the result. I mean I want to main thread to continue executing and no-wait for called method to get completed. I'm trying this snippet:
// The async method:
private static async Task LogAsync(Exception exception, string ip, MethodBase method, object parameters) {
// some stuff
}
// The caller methods:
public static void Log1(Exception exception, object parameters) {
LogAsync(exception, ip, method, parameters);
}
public static void Log2(Exception exception, object parameters) {
Task.Factory.StartNew(() => LogAsync(exception, ip, method, parameters));
}
public static async void Log3(Exception exception, object parameters) {
await LogAsync(exception, ip, method, parameters).ConfigureAwait(true);
}
public static async void Log4(Exception exception, object parameters) {
// I've tried even this one:
await LogAsync(exception, ip, method, parameters).ConfigureAwait(false);
}
As you can see, I tried different ways; but non of them give me what I want. Do you have any idea, what would help me?
See Question&Answers more detail:os