面试啦 - 提供专业面试问题及答案、面试技巧、助您成功面试!
您的当前位置:首页 > 面试题库 > IT面试题 > C#面试题 > 正文

使用C#编写创建一个线程的代码

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.”);
}
}
词条:c面试题
上一篇:如何手工释放资源 下一篇:编写一个类体现构造,公有,私有方法,静态,私有变量
与该文相关的文章

温馨提示:如果您对面试网有任何建议,请通过网站联系邮箱向我们反馈,感谢各位的建议与支持!