多线程

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Task t1 = new Task(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    System.Threading.Thread.Sleep(100);
                    Console.WriteLine("TASK1 do something" + i);
                }
            });

            Task t2 = new Task(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    System.Threading.Thread.Sleep(200);
                    Console.WriteLine("TASK2 do something" + i);
                }
            });

            Task t3 = new Task(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    System.Threading.Thread.Sleep(200);
                    Console.WriteLine("TASK3 do something" + i);
                }
            });
            t1.Start();
            t2.Start();
            t3.Start();
            Task.WaitAll(t1, t2, t3);
            Console.WriteLine("over");
            Console.ReadLine();
        }
    }
}
原文地址:https://www.cnblogs.com/hanmian4511/p/4554155.html