我有以下代码。这是一个带有单个文本框的表单。如果我myTimer_Tick
不是静态的,那么它工作正常 - 为什么?
namespace Ariport_Parking
{
public partial class AirportParking : Form
{
//instance variables of the form
static Timer myTimer;
public AirportParking()
{
InitializeComponent();
keepingTime(5000);
txtMessage.Text = "hello";
}
//method for keeping time
public void keepingTime(int howlong) {
myTimer = new Timer();
myTimer.Enabled = true;
myTimer.Tick += new EventHandler(myTimer_Tick);
myTimer.Interval = howlong;
myTimer.Start();
}
static void myTimer_Tick(Object myObject,EventArgs myEventArgs){
myTimer.Stop();
txtMessage.Text = "hello world";
}
}
}