例如,在我的项目中,我想在 5 分钟后显示消息或调用方法,如果用户没有点击特定按钮,我编写了这段代码
Boolean flage = false;
private void button1_Click(object sender, EventArgs e)
{
Timer Clock;
Clock = new System.Windows.Forms.Timer();
Clock.Interval = 1000;
Clock.Start();
Clock.Tick += new EventHandler(Timer_Tick);
}
public void Timer_Tick(object sender, EventArgs eArgs)
{
if (flage == false)
{
MessageBox.Show("after period of time ");
}
}
private void button2_Click(object sender, EventArgs e)
{
flage = true;
}
它保持显示消息框可以帮助我。