private void ThreadTask()
        {
            Form2 form2 = new Form2();
            AnimateWindow(form2.Handle, 1000, AW_VER_NEGATIVE | AW_ACTIVATE);//从下到上且不占其它程序焦点  
            Form2.lb.Text = "sadsadsad";
           
            //Thread.Sleep(10000);
            //Thread.SpinWait(10000);
            form2.Show();
            System.Timers.Timer t = new System.Timers.Timer(10000);  //实例化Timer类,设置间隔时间为10000毫秒;
            t.Elapsed += new System.Timers.ElapsedEventHandler(theout);  //到达时间的时候执行事件;  
            t.AutoReset = false;  //设置是执行一次(false)还是一直执行(true);  
            t.Enabled = true;  //是否执行System.Timers.Timer.Elapsed事件;  
        }

解决方案 »

  1.   

    form2弹出后有一段延时,然后再关闭。theout方法中写的就是关闭form2窗体的语句。以上代码我是放在一个线程中的。刚开始没用线程实现时可以达到预期效果,改用线程之后,窗体form2刚弹出就又消失了。想了好长时间也不明白是为什么,麻烦你解答一下
      

  2.   


                Timer t = new Timer();
                t.Interval = 10000;
                t.Tick += new EventHandler(theout);
                t.Start();
      

  3.   

    System.Windows.Forms.Timer 试试
      

  4.   

    大哥 试了 还是不行啊 并且t没有Tick这个方法
      

  5.   


    private void ThreadTask()
            {
              Form2 form2 = new Form2();
              AnimateWindow(form2.Handle, 1000, AW_VER_NEGATIVE | AW_ACTIVATE);//从下到上且不占其它程序焦点  
              Form2.lb.Text = "sadsadsad";
               
              form2.Show();
                
              t = new System.Windows.Forms.Timer();
              t.Interval = 10000;
              t.Tick += new EventHandler(t_Tick);
              t.Start();  
            }        void t_Tick(object sender, EventArgs e)
            {
                //到达时间的时候执行事件;
                //操作
            }
      

  6.   

    timer及其后面的几句就是延迟的代码啊
      

  7.   

    别用System.Windows.Forms.Timer 类,你只要用System.Threading.Timer 类,延迟操作自然是异步完成的。你同步操作Timer,其实它延迟后的执行却是异步的。
      

  8.   

    System.Threading.Timer t = new System.Threading.Timer(new TimerCallback(TimerProc1));
                t.Change(1000, 1000);        private void TimerProc1(object state)
            {
                System.Threading.Timer t = (System.Threading.Timer)state;
                //释放定时器资源
                  t.Dispose();            //执行流程1
                //
                //
                Console.WriteLine("流程1结束");            //开始流程2的延迟
                  System.Threading.Timer tt = new System.Threading.Timer(new TimerCallback(TimerProc2));
                tt.Change(1000, Timeout.Infinite);
            }        private void TimerProc2(object state)
            {
                System.Threading.Timer t = (System.Threading.Timer)state;
                //释放定时器资源
                  t.Dispose();            //执行流程2
                //
                //
                Console.WriteLine("流程2结束");            //开始流程3的延迟
                  System.Threading.Timer tt = new System.Threading.Timer(new TimerCallback(TimerProc3));
                tt.Change(1000, Timeout.Infinite);
            }        private void TimerProc3(object state)
            {
                System.Threading.Timer t = (System.Threading.Timer)state;
                //释放定时器资源
                  t.Dispose();            //执行流程3
                //
                //
                Console.WriteLine("流程3结束");
            }Change方法后面跟的第一个参数是延迟的毫秒数,自己调整。
    第二个参数是循环周期,你这里不用循环,所以可以设置为Timeout.Infinite。
    由于每次延迟执行后,都会调用t.Dispose(),所以不用怕资源的消耗,资源是及时释放的
      

  9.   

    http://topic.csdn.net/u/20091104/21/bc0e494b-6ec5-4a12-b063-6b443fbd80bd.html
      

  10.   

    楼上兄弟 我把我的程序改成了如下,可是还不行。
             private void ThreadTask()
            {
              Form2 form2 = new Form2();
              AnimateWindow(form2.Handle, 1000, AW_VER_NEGATIVE | AW_ACTIVATE);//从下到上且不占其它程序焦点  
              Form2.lb.Text = "sadsadsad";
               
              form2.Show();
                
              System.Threading.Timer t = new System.Threading.Timer(new TimerCallback(TimerProc1));
                t.Change(10000, 1000); 
            }
            private void TimerProc1(object state)
            {
                System.Threading.Timer t = (System.Threading.Timer)state;
                //释放定时器资源
                t.Dispose();        }