日期:2014-05-18 浏览次数:21171 次
using System;
using System.Threading;
public class Example
{
    public static void Main()
    {
        // Create an instance of the Example class, and start two
        // timers.
        Example ex = new Example();
        ex.StartTimer(2000);
        ex.StartTimer(1000);
        Console.WriteLine("Press Enter to end the program.");
        Console.ReadLine();
    }
    public void StartTimer(int dueTime)
    {
        Timer t = new Timer(new TimerCallback(TimerProc));
        t.Change(dueTime, 0);
    }
    private void TimerProc(object state)
    {
        // The state object is the Timer object.
        Timer t = (Timer) state;
        t.Dispose();
        Console.WriteLine("The timer callback executes.");
    }
}
------解决方案--------------------
public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }
       private void button1_Click(object sender, EventArgs e)
       {
           this.button1.Visible = false;
           Timer t= new Timer();
           t.Interval = 2 * 1000;
           t.Tick += new EventHandler(t_Tick);
           t.Start();
       }
       void t_Tick(object sender, EventArgs e)
       {
           this.button1.Visible = true;
           ((Timer)sender).Stop();
       }
   }