I generally say because you did not indicate which timer, but everyone has ticks ... like this:
you will need a counter in the class e.g.
int count;
which you initialize at the beginning of your timer and you will need a dateTime, for example
DateTime start;
which you initialize at the beginning of your timer:
start = DateTime.Now;
and in your selection method you will do:
if(count++ == 10 || (DateTime.Now - start).TotalSeconds > 2) timer.stop()
here is a complete example
public partial class meClass : Form { private System.Windows.Forms.Timer t; private int count; private DateTime start; public meClass() { t = new Timer(); t.Interval = 50; t.Tick += new EventHandler(t_Tick); count = 0; start = DateTime.Now; t.Start(); } void t_Tick(object sender, EventArgs e) { if (count++ >= 10 || (DateTime.Now - start).TotalSeconds > 10) { t.Stop(); }
source share