码迷,mamicode.com
首页 > 编程语言 > 详细

多线程

时间:2015-06-05 11:47:09      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

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)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!