C#中多线程Task

Task开启线程的方法:

           {
                Task task1 = new Task(() => Console.WriteLine($"task1 线程Id:" +
                    $"{Thread.CurrentThread.ManagedThreadId.ToString("00")}"));
                task1.Start();
            }
            { 
                Task task2=Task.Run(() => Console.WriteLine($"task2 线程Id:" +
                    $"{Thread.CurrentThread.ManagedThreadId.ToString("00")}"));
            }
            {
                TaskFactory taskFactory = new TaskFactory();
                taskFactory.StartNew(() => Console.WriteLine($"task2 线程Id:" +
                    $"{Thread.CurrentThread.ManagedThreadId.ToString("00")}"));
            }
            {
                TaskFactory taskFactory1 = Task.Factory;
                taskFactory1.StartNew(() => Console.WriteLine($"task2 线程Id:" +
                   $"{Thread.CurrentThread.ManagedThreadId.ToString("00")}"));
            }

  

posted @ 2020-01-17 15:14  石shi  阅读(595)  评论(0编辑  收藏  举报