设为首页 加入收藏

TOP

使用C#编写创建一个线程的代码?
2014-11-23 21:52:11 来源: 作者: 【 】 浏览:18
Tags:使用 编写 创建 一个 线程 代码

using System;
using System.IO;
using System.Threading ;
class MyThread{
public int count;
string thrdName;
public MyThread(string name){
count=0;
thrdName=name;
}
public void run(){
Console.WriteLine(thrdName+”starting.”);
do{
Thread.Sleep(500);
Console.WriteLine(“In”+thrdName+”, count is “+count);
count++;
}while(count<10);
Console.WriteLine(thrdName+” terminating.”);
}
}
class MultiThread{
public static void Main(){
Console.WriteLine(“Main thread starting.”);
MyThread mt=new MyThread(“Child #1″);
Thread newThrd=new Thread(new ThreadStart(mt.run));
newThrd.Start();
do {
Console.Write(“.”);
Thread.Sleep(100);
}while(mt.count!=10);
Console.WriteLine(“Main thread ending.”);
}
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇三星面试笔试 下一篇发网易游戏开发工程师笔试题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: