Running code at a given time interval

I would like to run the code every 1 minute, 15 minutes, etc. Is there a better way than after entering a timer with a time interval of 1 second. C # solution is ok too.

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
+3
source share
5 answers

You can check this message with a timer.

int startin = 60 - DateTime.Now.Second;
var t = new System.Threading.Timer(o => Console.WriteLine("Hello"), 
     null, startin * 1000, 60000);
+5
source

If you are doing heavy processing in it, itโ€™s better to write an application and write it using the Windows Task Scheduler.

+2
source

, 0 15 1, , , 1 , 15 , .

timers ( ), 1 , 15

, , .

+1

You can create a separate thread to constantly run the code and signal it to stop using the timer with a 15-minute or 1 minute. However, a better explanation of what you are trying to achieve would help everyone answer your question. If all you are trying to do is execute some code (and not repeat it several times), simple timers will make sense ... but your example was unclear.

+1
source

Create a Windows service to do this.

-2
source

Source: https://habr.com/ru/post/1726766/


All Articles