An entry point cannot be marked with the 'async' modifier

前端 未结 5 1814
甜味超标
甜味超标 2020-12-05 13:08

I copied below code from this link.But when I am compiling this code I am getting an entry point cannot be marked with the \'async\' modifier. How can I m

5条回答
  •  情深已故
    2020-12-05 13:26

    Starting from C# 7.1 there are 4 new signatures for Main method which allow to make it async(Source, Source 2, Source 3):

    public static Task Main();
    public static Task Main();
    public static Task Main(string[] args);
    public static Task Main(string[] args);
    

    You can mark your Main method with async keyword and use await inside Main:

    static async Task Main(string[] args)
    {
        Task getWebPageTask = GetWebPageAsync("http://msdn.microsoft.com");
    
        Debug.WriteLine("In startButton_Click before await");
        string webText = await getWebPageTask;
        Debug.WriteLine("Characters received: " + webText.Length.ToString()); 
    }
    

    C# 7.1 is available in Visual Studio 2017 15.3.

提交回复
热议问题