可以定义个变量么
private bool threadCanStop = false;void InvokeShowLight()
{
while(true)
{
Monitor.Enter(threadCanStop);
if(threadCanStop) break;
Monitor.Exit(threadCanStop);
..你的线程代码
}
}
如果你需要线程运行完停止了,就设置
Monitor.Enter(threadCanStop);
threadCanStop = true;
Monitor.Exit(threadCanStop);
private bool threadCanStop = false;void InvokeShowLight()
{
while(true)
{
Monitor.Enter(threadCanStop);
if(threadCanStop) break;
Monitor.Exit(threadCanStop);
..你的线程代码
}
}
如果你需要线程运行完停止了,就设置
Monitor.Enter(threadCanStop);
threadCanStop = true;
Monitor.Exit(threadCanStop);
{
while(threadCanStop)
{
..你的线程代码
}
}在主线程中只要设置threadCanStop=false就可以退出该线程。
正解~~~
再用CurrentCell指定那列
就可以取它的值
private ManualResetEvent threadCanStop = new ManualResetEvent (false);void InvokeShowLight()
{
while(!threadCanStop.WaitOne(100,false))
{
//做你的工作.
}
}//如果你需要线程运行完停止了,就设置
threadCanStop.Set();
threadCanStop.WaitOne(100,false): 意思是等待100毫秒,如果threadCanStop被主线程Set了,就返回true,从而退出while. 这里等待100毫秒是关键,如果写一个没有等待的While循环,CPU负荷太大,通常会上到100%.