C#大问题,高分求救!!!! 20

classTest(){staticvoidMain(){Threadth1=newThread(newThreadStart(h1));Threadth2=newThr... class Test()
{
static void Main()
{
Thread th1=new Thread(new ThreadStart(h1));
Thread th2=new Thread(new ThreadStart(h2));
th1.IsbackGround=true;
th2.IsbackGround=true;
th1.Start();

}
void h1()
{

Console.WriteLine("哈哈");
th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
}
不知道为什么就错了!~!~
不好意思是题目打错了!~因该是这样!~我要这样打出(呵呵)
class Test()
{
Thread th1;
Thread th2;
static void Main()
{
th1=new Thread(new ThreadStart(h1));
th2=new Thread(new ThreadStart(h2));
th1.IsbackGround=true;
th2.IsbackGround=true;
th1.Start();
}
void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
}
展开
 我来答
百度网友718369f09
2008-04-16 · TA获得超过676个赞
知道小有建树答主
回答量:291
采纳率:0%
帮助的人:288万
展开全部
//你可以用静态方法,参考以下代码:

//定义Class不能加括号
//class Test()
class Test
{
//Main是静态方法不能调直接用动态变量
//Thread th1;
//Thread th2;
static Thread th1;
static Thread th2;

static void Main()
{

th1 = new Thread(new ThreadStart(h1));
th2 =new Thread(new ThreadStart(h2));

//C#区分大小写
//th1.IsbackGround=true;
//th2.IsbackGround=true;
th1.IsBackground = true;
th2.IsBackground = true;

th1.Start();
}
//Main是静态方法不能调直接用动态方法
//void h1()
static void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
//Main是静态方法不能调直接用动态方法
//void h2()
static void h2()
{
Console.WriteLine("呵呵");
}
}

//----------------------------------------------------------//

//你也可以创那一个静态变量,使用它的动态方法,参考以下代码:

//定义Class不能加括号
//class Test()
class Test2
{

Thread th1;
Thread th2;
//使用t2创建th1和th2
static Test2 t2 = new Test2();

static void Main()
{

//th1 = new Thread(new ThreadStart(h1));
//th2 = new Thread(new ThreadStart(h2));
t2.th1 = new Thread(new ThreadStart(t2.h1));
t2.th2 = new Thread(new ThreadStart(t2.h2));

//C#区分大小写
//th1.IsbackGround=true;
//th2.IsbackGround=true;
t2.th1.IsBackground = true;
t2.th2.IsBackground = true;

t2.th1.Start();
}

void h1()
{
Console.WriteLine("哈哈");
t2.th2.Start();
}

void h2()
{
Console.WriteLine("呵呵");
}
}
lcg1986
2008-04-15 · TA获得超过3374个赞
知道大有可为答主
回答量:1858
采纳率:90%
帮助的人:1655万
展开全部
一楼正确
你在Main函数中声明的th1,th2
h1函数中可不知道th2为何物.

你把
Thread th1=new Thread(new ThreadStart(h1));
Thread th2=new Thread(new ThreadStart(h2));
放在Main函数的外面声明就没问题了
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
okbinbin
2008-04-16 · TA获得超过675个赞
知道小有建树答主
回答量:726
采纳率:0%
帮助的人:393万
展开全部
楼主你能看懂他们在说什么吗?其实你也看的不太清楚而已,你不如直接在摆渡搜索一下就可以得到答案的,不用这么浪费时间和得给分。。谢谢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
疯化血岳
2008-04-15 · TA获得超过111个赞
知道答主
回答量:118
采纳率:0%
帮助的人:88.9万
展开全部
你最后的时候把 th1 th2. Abort() 下,试试
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
敏锐又热烈的小丁香4
2008-04-14 · 超过28用户采纳过TA的回答
知道答主
回答量:203
采纳率:0%
帮助的人:0
展开全部
th2在h1方法中没有声明
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式