public class Timer
{
public delegate void Timer_Tick(object sender, EventArgs e);
public event Timer_Tick Tick;
System.Threading.Thread TimerThread = null;
public Int32 TimeoutFrequency {get;set;}
public Boolean TimerWorking {get;set;}
public void Start()
{
this.TimerWorking = true;
this.TimerThread = new System.Threading.Thread(new System.Threading.ThreadStart(RunTimer));
this.TimerThread.IsBackground = true;
this.TimerThread.Start();
}
public void Stop()
{
this.TimerWorking = false;
if (this.TimerThread.ThreadState == System.Threading.ThreadState.Running)
this.TimerThread.Abort();
}
private void RunTimer()
{
Int32 inc = 0;
while (this.TimerWorking)
{
inc++;
System.Threading.Thread.Sleep(1000);
if (inc >= this.TimeoutFrequency)
{
Tick(this, new EventArgs());
inc = 0;
}
}
}
}
Use this inside of the Timer control available in the Windows forms