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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top