我认为它不在 run.waitOne(); 等待
在处理代码行时,假设我想通过单击暂停按钮暂停这些代码行。它应该再次等待我单击相同的暂停以恢复相同的线程。但它根本不等待。任何想法来实现这一点?
ManualResetEvent run=new ManualResetEvent(false);
bool flag=true;
StartButton_Click(object sender,EventArgs e)
{
ThreadStart ts=new ThreadStart(startprocess);
Thread th=new Thread(ts);
th.Start();
}
private void StartProcess()
{
while(true)
{
if (parentform != null)
{
TestForm(parentform);
parentform = null;
}
else
{
if (a[0] == true)
{
value[0] = method1();//method1 return a double value
Thread.Sleep(500);
}
if (a[1] == true)
{
value[1] =method2();
Thread.Sleep(500);
}
if (a[2] == true)
{
value[2] = method3();
Thread.Sleep(500);
}
if (a[3] == true)
{
value[3] = method4();
Thread.Sleep(500);
}
if (a[4] == true)
{
value[4] =method5();
Thread.Sleep(500);
}
if (a[5] == true)
{
value[5] = method6();
Thread.Sleep(500);
}
run.WaitOne();
timer1.Stop();
DateTime now = DateTime.Now;
string datetime = Convert.ToString(now);
database.InsertTest(datetime,value[0], value[1], value[2], value[3], value[4],value[5]);
}
}
}
private void Pausebutton_Click(object sender, EventArgs e)
{
if (flag)
{
timer1.Enabled = true;
run.Set();
flag = false;
}
else
{
timer1.Enabled = false
run.Reset();
flag = true;
}
}