C#------------await

        public static async Task Main()
        {
            Task<int> downloading = TaskAsync();
            Console.WriteLine($"{nameof(Main)}: A");

            int bytesLoaded = await downloading;
            Console.WriteLine($"{nameof(Main)}: B---------Downloaded {bytesLoaded} bytes.");
        }

        private static async Task<int> TaskAsync()
        {
            Console.WriteLine($"{nameof(TaskAsync)}: C");

            var client = new HttpClient();
            byte[] content = await client.GetByteArrayAsync("https://nuget.hyc.com/");

            Console.WriteLine($"{nameof(TaskAsync)}: D");
            return content.Length;
        }

 

posted @ 2024-08-23 16:06  echo-efun  阅读(15)  评论(0)    收藏  举报