You can use void
(instead of Task
) as a return type of an asynchronous method. This will result in a "fire-and-forget" action:
public void DoStuff()
{
FireAndForgetAsync();
}
private async void FireAndForgetAsync()
{
await Task.Delay(1000);
throw new Exception(); //will be swallowed
}
As you are returning void
, you can not await
FireAndForgetAsync
. You will not be able to know when the method finishes, and any exception raised inside the async void
method will be swallowed.