C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# Async MainFrom C# 7.1, C# compiler allows us to create asynchronous Main method. It helps us to perform asynchronous tasks at entry level of the application. Main method may contain an await expression to perform asynchronous task. The using System.Threading.Tasks; namespace is used to access Task type. C# provides following valid asynchronous overloaded Main methods. public async static Task Main(); public async static Task C# Asynchronous Main Example
using System;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
// Async Main method
public async static Task Main(string[] args)
{
Console.WriteLine("This is async Main method");
}
}
}
Output: This is async Main method In this example, an asynchronous Main method calls to another async method. C# Asynchronous Main Method Example
using System;
using System.Threading.Tasks;
using System.Net.Http;
namespace CSharpFeatures
{
class AsynchronousMethod
{
// Asynchronous Main method
async static Task Main(string[] args)
{
TaskOutput: length: 36006
Next TopicC# Default Expression
|