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")}")); }