We have been using async/await extensively because we need to access third-party async APIs. We are not doing UI and rarely need to use ASP.NET, we mainly write console applications. So most of our code generally looks like (hugely simplified):
static void Main()
{
handle.Wait();
}
static async Task handle()
{
while(true)
{
var a = await GetSomeThing();
var b = await GetSomeThingElse(a);
await DoSomething(a,b);
}
}
My limited understanding of await
is that it frees the program to work on other tasks while the operation completes; but since each operation is entirely dependent on the one before there is nothing else that the program could process in the meantime. So what practical difference is there between the (recommended?) way above and the alternative:
static void Main()
{
while(true)
{
var a = GetSomeThing().Result;
var b = GetSomeThingElse(a).Result;
DoSomething(a,b).Wait();
}
}
Some respondents allude to doing 'other work' or not blocking threads when calling 'handle' many times. Forgive me if I was not clear. There are no other tasks that I am aware of. We are writing essentially single-threaded sequential code where each stage is entirely dependent on the stage before and where we only use async because the third-party APIs require us to do so.
I should also emphasise that I am not 'opposed' to using the async syntax, I am merely trying to understand what benefit it actually provides in our use-case.