I have an async
Web API called MyCustomAPI
to read some data from an API hosted in Azure, process it and save it in a SQL server. I have made the MyCustomAPI
Web API, Azure API and the call to the SQL server as async
calls. I have to call the ReadAndSaveDataCalleeAsync
that calls the Web API method MyCustomAPI.ReadAndSaveDataAsync()
in a command line app.
The problem that I have is I can't make Async
calls in the Main
method. I have to call with a Wait()
method. This will make the Main
method to wait, so make it synchronous.
static void Main()
{
ReadAndSaveDataCalleeAsync().Wait(); // Calls MyCustomAPI.ReadAndSaveDataAsync
}
I think this defeat the purpose of making (1) MyCustomerAPI (2) Azure API (3) Database calls async
. My understanding is that I have to make all the calls async
to get the benefit of the Operating System handle the resources and threads for all the methods very efficiently.
How can I make the Command line app async
to get the benefit of all other services async
feature?