.NET-异步操作

感觉可以用于log日志的东西,这个东西他还是会走的但是不会影响你下一步的操作,你下一步还是正常怎么操作就怎么操作!

这样可以给用户免掉一些没必要的等待。

 static void Main(string[] args)
        {
            //   异步同步
            Console.WriteLine("我是主线程,线程ID:{0}", Thread.CurrentThread.ManagedThreadId);
            //asd();
            TaskMethod();
            Console.WriteLine("Hello World!");
            string str = Console.ReadLine();
            Console.WriteLine(str);
             str = Console.ReadLine();
            Console.WriteLine(str);
             str = Console.ReadLine();
            Console.WriteLine(str);
             str = Console.ReadLine();
            Console.WriteLine(str);
            Console.ReadLine();
        }
        static async  void TaskMethod()
        {
            await Task.Run(() =>
            {
                Thread.Sleep(50000);
            });
            Console.WriteLine(123);
        }
原文地址:https://www.cnblogs.com/ya-jun/p/11662301.html