async await

async await 成對出現。執行結果爲: end  async async

        static void Main(string[] args)
        {

            DoAsync();
            
            Console.WriteLine("end");

            Console.ReadLine();
        }

        private static async Task DoAsync()
        {
            string ss = await ReturnAsync();
            Console.WriteLine(ss);
        }

        private static async Task<string> ReturnAsync()
        {
            return await Task<string>.Run(() =>
            {
                Thread.Sleep(5000);
                return "async";
            });
        }
相關文章
相關標籤/搜索