using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;//添加线程引用
namespace 线程练习1
{
public partial class Form1 : Form
{
public Thread xf = new Thread(kl);
Thread xc1 = new Thread(xcxc1);
public Form1()
{
InitializeComponent();
}
static void xcxc1()
{
MessageBox.Show("执行了线程1");
}
private void button2_Click(object sender, EventArgs e)
{
Thread xc2 = new Thread(xcxc2);
}
static void xcxc2()
{
MessageBox.Show("执行了线程1");
}
static void kl()
{
MessageBox.Show("kl1");
}
private void button3_Click(object sender, EventArgs e)
{
xf.Start();//线程开始 执行
xf.Suspend();//挂起线程
xf.Interrupt();//唤醒 线程//中断处于join状态的线程
Thread.Sleep(5000);//线程等待5S后继续 运行。
xf.Abort();//结束线程
xc1.Start();
}
}
}
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;//添加线程引用
namespace 线程练习1
{
public partial class Form1 : Form
{
public Thread xf = new Thread(kl);
Thread xc1 = new Thread(xcxc1);
public Form1()
{
InitializeComponent();
}
static void xcxc1()
{
MessageBox.Show("执行了线程1");
}
private void button2_Click(object sender, EventArgs e)
{
Thread xc2 = new Thread(xcxc2);
}
static void xcxc2()
{
MessageBox.Show("执行了线程1");
}
static void kl()
{
MessageBox.Show("kl1");
}
private void button3_Click(object sender, EventArgs e)
{
xf.Start();//线程开始 执行
xf.Suspend();//挂起线程
xf.Interrupt();//唤醒 线程//中断处于join状态的线程
Thread.Sleep(5000);//线程等待5S后继续 运行。
xf.Abort();//结束线程
xc1.Start();
}
}
}