c# 中如何单击一个按钮启动一个线程

来源:百度知道 编辑:UC知道 时间:2024/05/15 17:04:54
c# 中如何单击一个按钮启动一个线程,单击另一个按钮阻塞这个线程,再单击第三个按钮又使该线程挂起?
且这几个按钮可以在运行中任意点击,如果不合乎逻辑则给出错误提示。(最好请给出代码)好回答追加分数!
我说的是在windows窗体设计中的设计,不是在控制台上的程序设计

给你个DEMO
//*********************** ThreadTest.cs ********************
using System;
using System.Threading;
class ThreadTest
{
public static void threadMethod()
{
for (int i=0; i<10; i++)
{
Console.WriteLine("threadMethod: {0}", i);
Thread.Sleep(1);
}
}
public static void Main()
{
Console.WriteLine("Main()线程: 启动第2个线程");
Thread thread=new Thread(new ThreadStart(threadMethod));
thread.Start();
for (int i=0; i<4; i++)
{
Console.WriteLine("Main()线程: 运行 #{0} 项工作",i);
Thread.Sleep(0);
}
Console.WriteLine("Main()线程: 调用 Join() 方法\n" +
" 等待 threadMethod() 执行完毕");
thread.Join();
Console.WriteLine("Main()线程: threadMethod.Join 已" +
"经运行完毕");
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;