Base
- keyword async await
- The return value of an asynchronous method is Task<T>, if there is no return value, use Task instead of void
- Call: await asynchronous method (parameter)
- Get T in the return value: T (type passed in by generics) identifier=await asynchronous method (parameter)
- The await asynchronous method appears in the method, the method must be decorated with async
case
using System;
using System.IO;
using System.Threading.Tasks;
namespace TaskAysnc
{
class Program
{
async static Task Main(string[] args)
{
string fileName = @"D:\Program Files (x86)\OneDrive\桌面\异步\1.txt";
await File.WriteAllTextAsync(fileName, "异步写入");
string result = await File.ReadAllTextAsync(fileName);
Console.WriteLine(result);
}
}
}