我有这个功能,我试图将计时器事件作为单独的线程调用,但是当我单击页面中的任何按钮或在 asp.net 页面中执行任何操作时,计时器会停止一秒钟。
请帮助如何在页面中不受另一个控件影响的情况下并行运行它,因为计时器应该每秒钟运行一次,并且它不应该在 ui 中停止。
Thread obj = new Thread(new ThreadStart(timer));
obj.Start();
obj.IsBackground = true;
protected void timer()
{
Timer1.Interval = 1000;
Timer1.Tick += new EventHandler<EventArgs>(Timer1_Tick);
Timer1.Enabled = true;
}
public void TimerProc(object state)
{
fromTime = DateTime.Parse(FromTimeTextBox1.Text);
tillTime = DateTime.Parse(TillTimeTextBox1.Text);
DateTime currDateTime = System.DateTime.Now;
TimeSpan interval = tillTime - currDateTime;
if (tillTime <= currDateTime)
{
ExamOverPanel1.Visible = true;
QuestionPanel.Visible = false;
ListBox2.Visible = false;
StatusPanel1.Visible = false;
VisitLaterLabel.Visible = false;
}
else
{
minLabel.Text = string.Format("{0:00}:{1:00}:{2:00}", (int)interval.TotalHours, interval.Minutes, interval.Seconds);
}
}