如果是顺序执行的话,那就初始时,将第一个timer的enable=true,其他为false
第一个中写timer1.enable=false;
....
timer2.enable=true;//开启第二个

解决方案 »

  1.   


    贴代码            System.Timers.Timer t = new System.Timers.Timer(3000);
                t.Elapsed += new System.Timers.ElapsedEventHandler(theout);
                t.AutoReset = true;
                t.Enabled = true;        public void theout(object source, System.Timers.ElapsedEventArgs e)
            {
    //执行压缩
                                    string strFilePaht = @"D:\Back\131121082103.txt";
                                    string strFileName = System.IO.Path.GetFileName(strFilePaht);
                                    string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(strFilePaht);
                                    GetFileToZip(strFilePaht, strFileName, @"d:\\Back\\" + fileNameWithoutExtension + ".zip");        }比如theout执行压缩需要10秒。但是Timer只给了3秒。怎么操作让theout执行完成之后,才进行下一次操作。
      

  2.   

    加一个全局变量作为标识试试。初始化为true,每次开始执行theout时判断这个值是不是true,是true再开始执行,否则直接跳出theout。theout开始执行后,将该全局变量设置为false,执行完后再设置为true。
      

  3.   

    int inProcessing = 0;
    void theout(object source, System.Timers.ElapsedEventArgs e)
    {
        if (Interlocked.CompareExchange(ref inProcessing, 1, 0) == 0)
        {
            try
            {
               // your code here...
            }
            finally
            {
                inProcessing = 0;
            }
        }
    }
      

  4.   

    你可以在执行你的方法的时候  停掉timer  执行完之后再开启像一楼说的那样