Async Main in Console App Visual Studio

I'm a software consultant who loves to build projects and share my learnings on this blog.
Search for a command to run...

I'm a software consultant who loves to build projects and share my learnings on this blog.
No comments yet. Be the first to comment.
Azure Functions is a powerful serverless compute platform, and Azure App Service handles a lot of the underlying configuration for you out of the box. However, there are scenarios where you may want t

If you’ve been exploring Azure AI learning paths or watching older demos, you’ve probably run into something confusing: The documentation and training links often reference Foundry (Classic) But the portal you’re using today might show Foundry (New...

In today's digital age, speed is paramount for web and mobile applications. Users expect instantaneous responses, and any delay can lead to a poor user experience and loss of engagement. Therefore, as developers, it's crucial to build web APIs that a...

Loops are fundamental constructs in any programming language. But have you ever wondered if there are any performance differences between them? For small collections, the difference might be negligible, but what about handling a million or 10 million...

When using an Azure Function app, it is necessary to connect it to a storage account, often referred to as Host storage. This storage is utilized by the Functions runtime, as well as by various triggers and bindings to coordinate between multiple run...

Many times we want to create some Pocs for our project wherein we test out other libraries, frameworks, NuGet packages, etc., and a lot of these would be implementing asynchronous programming. Which means, to call these methods exposed by the libraries, NuGet packages, etc. you would have to do a await in your console app. And as you are aware, Main method of Console App needs to be a static void Main(string[] args) and if you try to make the Main method async, you would get the error :

There are many workarounds for making the async calls from Main method, but I like to keep the Main method async and do an await inside it just like any other method. And this is now possible with C# version greater than 7.1
To do so, Right click on your project and select Properties and navigate to the Build Tab. There, click on Advanced button at the bottom.

In the Advanced menu, for the Language Version chose any c# version greater than 7.1

In case you can't see C# 7.1 or greater, please install any pending updates to your Visual Studio. And now you can change the Main method to :
static async Task Main(string[] args)
and do the await inside it.
