Home [C# 筆記] 將主程式進入點 Main()方法改成 async 非同步
Post
Cancel

[C# 筆記] 將主程式進入點 Main()方法改成 async 非同步

預設的 Console 應用程式

通常剛建立好一個 Console 應用程式專案,其主程式 Program.cs 的內容如下:

1
2
3
4
5
6
7
8
9
10
namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Your code here
        }
    }
}

改成 async 非同步 Main() 方法

加上asyncvoid 改成 Task

1
2
3
4
5
6
7
8
9
10
namespace ConsoleApp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Your code here
        }
    }
}

深入理解 C# 7.1 提供的 async 非同步 Main() 方法

This post is licensed under CC BY 4.0 by the author.