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

Thread线程初探

时间:2015-01-21 22:00:33      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Threading;

class Example
{
    static void Main()
    {
        TimeSpan interval = new TimeSpan(0, 0, 2);

        for (int i = 0; i < 5; i++)
        {
            Console.WriteLine("Sleep for 2 seconds.");
            Thread.Sleep(interval);
        }

        Console.WriteLine("Main thread exits.");
    }
}
/* This example produces the following output:

Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Main thread exits.
 */

每次输出

"Sleep for 2 seconds." 都会停留2秒

Thread线程初探

标签:

原文地址:http://www.cnblogs.com/holyson/p/4240005.html

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