我有这个函数,我试图调用定时器事件作为单独的线程,但是当我点击页面中的任何按钮或做任何事情在ASP .net页面,然后定时器停止一秒。并行处理定时器的事件与主线程在asp.net c#
请帮助如何在没有页面中另一个控件的效果的情况下运行paralley,因为计时器应该每秒运行一次,并且不应该停在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);
}
}
我实现了,但计时器没有运行每秒。如何改变每秒的时间? – 2013-03-05 09:24:32
@Nishantverma“TimerProc”方法每秒运行一次。不需要其他操作。你在'TimerProc'中放了什么? – 2013-03-05 09:32:29
我没有调试,发现它的运行速度每秒但没有更新UI.plz检查 – 2013-03-05 09:34:23