开发者

Run a code in given time interval

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 mi开发者_C百科n
End If


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);


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


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.


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.


Create a windows-service to do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜