1. Expalin
https://blog.darkthread.net/blog/async-aspnet/
2. code
https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/operators/await
---
using System;
using System.Net.Http;
using System.Threading.Tasks;
public class AwaitOperator
{
public static async Task Main()
{
Task<int> downloading = DownloadDocsMainPageAsync();
Console.WriteLine($"{nameof(Main)}: Launched downloading.....1\n");
int bytesLoaded = await downloading;
Console.WriteLine($"{nameof(Main)}: Downloaded {bytesLoaded} bytes.....4\n");
}
private static async Task<int> DownloadDocsMainPageAsync()
{
Console.WriteLine($"{nameof(DownloadDocsMainPageAsync)}: About to start downloading.....2\n");
var client = new HttpClient();
byte[] content = await client.GetByteArrayAsync("https://docs.microsoft.com/en-us/");
Console.WriteLine($"{nameof(DownloadDocsMainPageAsync)}: Finished downloading.....3");
return content.Length;
}
}
---
3. online c#
https://dotnetfiddle.net/
dotnet fileter choose .netcore3.0
4.
https://stackoverflow.com/questions/19335451/async-and-await-are-not-working
5. Very goodd
https://www.huanlintalk.com/2016/01/async-and-await.html
沒有留言:
張貼留言