C# How to start an async method without await its complete?

前端 未结 6 1452
醉酒成梦
醉酒成梦 2021-02-05 08:12

Sometimes I need to start an async job which works very slow. I don\'t care if that job success and I need to continue working on my current thread.

Like sometimes I nee

6条回答
  •  春和景丽
    2021-02-05 08:42

    A standalone discard is the best way to avoid this warning.

    _ = Task.Run(() =>  _emailService.SendEmailAsync());
    

    Discards are dummy variables and can be used to ignore the Task object returned by an asynchronous operation.

    https://docs.microsoft.com/en-us/dotnet/csharp/discards#a-standalone-discard

提交回复
热议问题