多线程

时间:2015-06-05 11:43:54   收藏:0   阅读:277
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();
        }
    }
}

原文:http://www.cnblogs.com/hanmian4511/p/4554155.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!