System.Threading.Timer example to run and display seconds until you click a button
- by Roy
Hi, I am having some issues creating an asp.net page using C#
When you first click a button it starts the display of seconds via a label control.
When you click the button again the seconds stop.
Currently my code behind looks like this:
System.Threading.Timer Timer;
bool endProcess = false;
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
Timer = new System.Threading.Timer(TimerCallback, null, 10, 10);
}
private void TimerCallback(object state)
{
Label1.Text = i.ToString();
i++;
if (endProcess == true)
{
Timer.Dispose();
return;
}
}
public void Button1_Click(object sender, System.EventArgs e)
{
endProcess = true;
}