If you call an asynchronous method it will run asynchronously whether you await the returned task or not.
await doesn't affect how the method executes, only how you as the caller deals with it. You can call the async method, get the task and await it right away (which is the simplest option). That will enable you to write code that looks synchronous but runs asynchronously as await basically registers the rest of the code after it as a callback to be executed only after the awaited task is completed. This doesn't block in the traditional since as no thread is blocked, but the code flow will be sequential:
async Task LargerProcessAsync()
{
if (condition)
{
await ReportSomethingHappenedAsync();
}
// do other stuff
}
However, you don't absolutely need to do that. You can get the task back, do other stuff and only then await it:
async Task LargerProcessAsync()
{
Task task = null;
if (condition)
{
task = ReportSomethingHappenedAsync();
}
// do other stuff
if (task != null)
{
await task;
}
}
Or you can simply remove the await completely. You should realize though that this can be dangerous as the task can be faulted and the exception can go unobserved and that's why it's discouraged. There are several ways to do this right, but they aren't simple. You can use Task.ContinueWith:
void LargerProcess()
{
if (condition)
{
ReportSomethingHappenedAsync().ContinueWith(task =>
{
try
{
task.Wait();
}
catch (Exception exception)
{
// handle exception
}
})
}
// do other stuff
}
Or for ASP.Net look at Fire and Forget on ASP.NET