ManualResetEvent 运用
ManualResetEvent _handle = new ManualResetEvent(true);//设置为true时,则为开,flase反之;
void _timer_Elapsed(object sender, ElapsedEventArgs e) {
try{
// WaitOne 发现信号为开,则允许进入执行
if (_handle.WaitOne(0)){
_handle.Reset();//马上设置关, 阻止其它线程从WaitOne进入
Thread thread = new Thread(_ThreadProc);
thread.IsBackground = false;
thread.Start();
}
}
catch (Exception ex){
//todo
}
}
void _ThreadProc(){
try{
ImportCommand cmd = new ImportCommand();
cmd.Execute();
}catch{
//todo
}
finally{
_handle.Set();//设置开, 让其它线程可以从WaitOne进入
}
}