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进入

            }

        }

 

相关文章:

  • 2021-08-18
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2021-04-30
  • 2021-05-29
  • 2021-11-22
  • 2021-08-14
猜你喜欢
  • 2021-10-20
  • 2022-12-23
  • 2021-08-18
相关资源
相似解决方案