- public partial class Form1 : Form
- {
- delegate void setnumdelegate(string text);
- setnumdelegate setTextDel;
- public Form1()
- {
- InitializeComponent();
- setTextDel = new setnumdelegate(this.SetText);
- }
- private void SetText(string text)
- {
- label1.Text = text;
- }
- private bool iforno=true;
- private void button1_Click(object sender, EventArgs e)
- {
-
- if (button1.Text == "开始摇奖")
- {
- Thread th = new Thread(new ThreadStart(this.setnumber));
- button1.Text = "停";
- th.IsBackground = true;
- th.Start();
-
- }
- else
- {
- button1.Text = "开始摇奖";
- label3.Text = label1.Text;
- iforno = false;
- //Thread.CurrentThread.Abort();
- }
- }
- private void setnumber()
- {
- //label1.Text = i.ToString();
- while (iforno)
- {
- Random seed = new Random();
- label1.Invoke(setTextDel, seed.Next(10).ToString());
- Thread.Sleep(100);
- }
- }
- }
复制代码 我点击开始摇奖后,点停止也停止了。 但是再次点开始摇奖就不行了。我知道应该那个线程还没停止的原因。该如何做啊??? |