Posted in 面试题 onJanuary 22, 2013
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 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.”);
}
}
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 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#编写创建一个线程的代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@