我在处理一个按纽点击事件,一开始按纽显示 "自动扫描",按下后线程启动,按纽标签变成"扫描暂停",按下后线程暂停(t.sustend), 标签变成"继续扫描",线程继续 t.Resume(),.但是现在的问题是 按下扫描后,线程停不下来,事件仍然在继续,但是 t.threadstate 的状态却是 unstart,奇怪了,明明线程已经启动了,为什么还是unstart状态呢??请高手指点,谢谢
private void autoscan_Click(object sender, EventArgs e)
{
huawangge_test = new huawangge(pictureBox6, true, 0, 0,20,20, 10,10, 0, 0, 100);
t = new Thread(new ThreadStart(huawangge_test.drawgrid));
//System.Threading.ThreadState state=t.ThreadState ;
if (autoscan.Text == "自动扫描")
{
t.Start();
state = t.ThreadState;
autoscan.Text = "暂停扫描";
}
else if (autoscan.Text == "暂停扫描")
{
if (t.ThreadState == System.Threading.ThreadState.Running )
{
t.Suspend();
}
autoscan.Text = "继续扫描";
}
else if (autoscan.Text == "继续扫描")
{
if (t.ThreadState ==System.Threading.ThreadState.Suspended)
{
t.Resume();
}
autoscan.Text = "停止扫描";
}
}
private void autoscan_Click(object sender, EventArgs e)
{
huawangge_test = new huawangge(pictureBox6, true, 0, 0,20,20, 10,10, 0, 0, 100);
t = new Thread(new ThreadStart(huawangge_test.drawgrid));
//System.Threading.ThreadState state=t.ThreadState ;
if (autoscan.Text == "自动扫描")
{
t.Start();
state = t.ThreadState;
autoscan.Text = "暂停扫描";
}
else if (autoscan.Text == "暂停扫描")
{
if (t.ThreadState == System.Threading.ThreadState.Running )
{
t.Suspend();
}
autoscan.Text = "继续扫描";
}
else if (autoscan.Text == "继续扫描")
{
if (t.ThreadState ==System.Threading.ThreadState.Suspended)
{
t.Resume();
}
autoscan.Text = "停止扫描";
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货