我正在使用计时器每 2 秒将文本输出到文本框。但似乎它不起作用。知道什么是错的。这是我的代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static System.Timers.Timer aTimer;
public void BtnGenData_Click(object sender, EventArgs e)
{
aTimer = new System.Timers.Timer(10000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Enabled = true;
}
public static void OnTimedEvent(object source, ElapsedEventArgs e)
{
string GenData = "Welcome";
Form1 frm1 = new Form1();
frm1.TboxData.AppendText(GenData.ToString());
}
}
实际上我没有看到任何输出。