System.Threading.Timer example to run and display seconds until you click a button
Posted
by Roy
on Stack Overflow
See other posts from Stack Overflow
or by Roy
Published on 2010-05-09T00:52:47Z
Indexed on
2010/05/09
0:58 UTC
Read the original article
Hit count: 245
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;
}
© Stack Overflow or respective owner