Timer in a class

  • Thread starter Thread starter MAY
  • Start date Start date
M

MAY

hi,

How to enable timer in a custome class, how to override the EventHandler of
the timer?


Thanks

MAY
 
Hi MAY,

There are at least three timers to choose from, but the most common one is System.Windows.Forms.Timer.

using System.Windows.Forms;

public class MyClass
{
Timer myTimer;
public MyClass() // constructor
{
myTimer = new Timer();
myTimer.Tick += new EventHandler(MyTickEvent);
myTimer.Interval = 100; // interval in ms
myTimer.Start();
}

private void MyTickEvent(object sender, EventArgs e)
{
// code to execute for each tick
}
}

Happy coding!
Morten Wennevik [C# MVP]
 
Back
Top