tags:

views:

256

answers:

5

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
A: 

Create a windows-service to do this.

this. __curious_geek
but still he needs to know when 15 mins passed and use a timer :)
TheVillageIdiot
You can use a timer inside your windows service. Primary reason to use windows-service is that the life-cycle of a windows-service is well-suited to this situation.
this. __curious_geek
+1  A: 

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.

Alon
+2  A: 

If you are doing some heavy processing in it, then better write an app and schedule it using windows task scheduler.

TheVillageIdiot
+2  A: 

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);
SwDevMan81
+1  A: 

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.

Siege