C#线程问题 急死我啦 帮帮忙- -!
这个是我做的摇奖机的一个东东,我这样写的线程没有问题。但是我发现点击了停止按钮(STOP启动按钮事件那里),这些显示的9个数字都是一模一样的,我再点击开始(Start启动按钮事件那里)。他就报错,大家帮帮忙 ,偶郁闷啦
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace 摇奖机
{
public partial class ERNIE : Form
{
private Point mouseOffset;//定义一个变量,用于存放鼠标的坐标
private bool isMouseDown = false;//定一个布尔变量,用于判断鼠标状态
//Thread[] th = new Thread[9];
ThreadStart t;
Thread th1;
Thread th2;
Thread th3;
Thread th4;
Thread th5;
Thread th6;
Thread th7;
Thread th8;
Thread th9;
public ERNIE()
{
InitializeComponent();
th1 = new Thread(new ThreadStart(rnd1));
th2 = new Thread(new ThreadStart(rnd2));
th3 = new Thread(new ThreadStart(rnd3));
th4 = new Thread(new ThreadStart(rnd4));
th5 = new Thread(new ThreadStart(rnd5));
th6 = new Thread(new ThreadStart(rnd6));
th7 = new Thread(new ThreadStart(rnd7));
th8 = new Thread(new ThreadStart(rnd8));
th9 = new Thread(new ThreadStart(rnd9));
//for (int i = 0; i < 9; i++)
//{
//th[i] = new Thread(t);
// }
}
//===============================================Start启动按钮事件=======================================
public void BTstart_Click(object sender, EventArgs e)
{
ERNIE.CheckForIllegalCrossThreadCalls = false;
th1.Start();
th2.Start();
th3.Start();
th4.Start();
th5.Start();
th6.Start();
th7.Start();
th8.Start();
th9.Start();
}
//===============================================STOP启动按钮事件=======================================
private void button1_Click(object sender, EventArgs e)
{
th1.Abort();
th2.Abort();
th3.Abort();
th4.Abort();
th5.Abort();
th6.Abort();
th7.Abort();
th8.Abort();
th9.Abort();
LB10.Text = LB1.Text;
LB11.Text = LB2.Text;
LB12.Text = LB3.Text;
LB13.Text = LB4.Text;
LB14.Text = LB5.Text;
LB15.Text = LB6.Text;
LB16.Text = LB7.Text;
LB17.Text = LB8.Text;
LB18.Text = LB9.Text;
}
//===============================================线程控制随机数==========================================
public void rnd1()
{
Random r = new Random();
int x = r.Next(0,10);
LB1.Text=x.ToString();
Thread.Sleep(10);
rnd1();
}
public void rnd2()
{
Random r = new Random();
int x = r.Next(0,10);
LB2.Text = x.ToString();