您的位置:首页 > 编程语言 > C#

C#中简单实现多线程

2006-04-16 09:37 447 查看
感觉用C#进行开发就是快

using System;
using System.Threading;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Thread thread1 = new Thread(new ThreadStart(Method1));
Thread thread2 = new Thread(new ThreadStart(Method2));
thread1.Start();
thread2.Start();

}
public static void Method1()
{
while(true)
{
Console.WriteLine("this is thread : 1");
Thread.Sleep(1000);

}

}
public static void Method2()
{
while (true)
{
Console.WriteLine("this is thread : 2");
Thread.Sleep(1520);
}

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: