Reputation:
I would like to run a code every 1 minute ,15 minute etc Is there any better way than following put in the timer control with time interval 1 sec. A c# solution is also ok.
If Now.Minute Mod 15 = 0 Then
'run code for 15 min
End If
If Now.Minute Mod 1 = 0 Then
'run code for 1 min
End If
Upvotes: 3
Views: 8987
Reputation: 2654
You could create a separate thread to run the code continuously, and signal it to stop using a 15-minute or 1-minute timer. A better explanation as to what you're trying to achieve would assist everyone in answering your question, however. If all you're trying to do is execute some code (and not repeatedly execute it), simple timers would make sense... but your example was unclear.
Upvotes: 1
Reputation: 50028
You could check out this post using a timer.
int startin = 60 - DateTime.Now.Second;
var t = new System.Threading.Timer(o => Console.WriteLine("Hello"),
null, startin * 1000, 60000);
Upvotes: 6
Reputation: 40527
If you are doing some heavy processing in it, then better write an app and schedule it using windows task scheduler.
Upvotes: 2
Reputation: 4952
this form has a flow, in minute 0 and every 15 min, the code for minute 1 will possibly not run since the check for 1 minute will wait until the code for 15 minutes is done which could take time.
use two timers (if the two codes are not related) one will go off every 1 minutes and the other will go every 15 minutes
or if possible you can use the windows scheduler service.
Upvotes: 1