我在 Windows 窗体应用程序中遇到了计时器问题。需要 Timer 记录归档时间的归档器。但是有什么东西打断了计时器?
我怀疑是溪流。关于什么可能导致计时器被中断的任何建议?
public partial class Form1 : Form
{
int timerCounter = 0;
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
timer.Interval = 1000;
timer.Enabled = true;
}
public void button2_Click(object sender, EventArgs e)
{
timer.Start();
timer.Tick += new EventHandler(timer1_Tick);
// code for archiving, streams
timer.Stop();
MessageBox.Show("Archive was created! :)");
}
public void timer1_Tick(object sender, EventArgs e)
{
this.label7.Text = (++timerCounter).ToString();
}
}