Reputation: 15039
I have a c# windows service with a timer that executes a process every 5 minutes.
I don't want to create other process to execute a task every 30 minutes, so is it possible within the same timer timer_Elapsed event to do that logic? any clue?
Thanks a lot,
Upvotes: 0
Views: 155
Reputation: 729
You could increment a variable every time the timer elapses, and when that variable reaches 6, you reset it to 0 and execute your 'once every 30 minute' code. Also, creating a new (winform) timer does not create a new thread as far as I know.
int TimerVariable=0;
TimerEvent(object sender,eventargs e)
{
TimerVariable++;
if(TimverVariable>=6)
{
//Execute the once every 30 min code
}
//Execute the once every 5 min code.
}
Upvotes: 1
Reputation: 73442
Well, you could just use a counter and check it against 6
(30000/5000) and reset it back to zero when done.
private int counter = 0;
private void TimerCallback()
{
counter++;
if(counter >=6)
{
//Your 30 seconds code here
counter = 0;
}
}
Upvotes: 0