怎么用取消键停止辅助线程???代码如下
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace VC2008programm
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
// private Thread thread = new Thread(ThreadProc);
private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(ThreadProc));
thread.IsBackground = true;
thread.Start();
this.button1.Enabled = false;
}
public void ThreadProc()
{
for (int i = 0; i < 500; i++)
{
OutText(i.ToString());
Thread.Sleep(100);
}
}
public delegate void OutDelegate(string text);
public void OutText(string text)
{
if (txt.InvokeRequired)
{
OutDelegate outdelegate = new OutDelegate(OutText);
this.BeginInvoke(outdelegate, new object[] { text });
return;
}
txt.Items.Add(text);
// txt.AppendText("\t\n");
}
private void Form4_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
停止辅助线程的语句怎么写?
}
}
}