async异步调用的简单用法

代码如下:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace _async_Task
{
    class Program
    {
        public static async Task<string> Get()
        {
            return await Ge();
        }
        public static Task<string> Ge()
        {
            return Task.Run(() =>
            {
                Thread.Sleep(5000);
                Console.WriteLine("test");

                return "5";
            });
        }
        static void Main(string[] args)
        {
            var  s = Get();
            Console.WriteLine(0);

            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine(0);

        }
    }
}

  

posted @ 2021-08-29 22:35  艾特-天空之海  阅读(116)  评论(0编辑  收藏  举报