I have a timer tick that I would like to kick off my backgroundworker every 30 minutes. What is the equivalent value of 30 minutes for a timer tick?
Below follows the code:
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Interval = (1000) * (1);
_timer.Enabled = true;
_timer.Start();
void _timer_Tick(object sender, EventArgs e)
{
_ticks++;
if (_ticks == 15)
{
if (!backgroundWorker1.IsBusy)
{
backgroundWorker1.RunWorkerAsync();
}
_ticks = 0;
}
}
I am not sure if this is the best way or if anyone has a better suggestion.
The Interval property of a timer is specified in milliseconds, not ticks.
Therefore, for a timer which fires every 30 minutes, simply do:
However, I’m not clear what the
Tickevent you use is. I think you mean Elapsed?EDIT As CodeNaked makes clear, you are talking about the System.Windows.Forms.Timer, not the System.Timers.Timer. Luckily, my answer applies to both 🙂
Finally, I don’t understand why you maintain a count (
_ticks) within yourtimer_Tickmethod. You should re-write it as follows: