我想每 1 分钟、15 分钟等运行一次代码有没有比将时间间隔为 1 秒的计时器控件放入其中更好的方法。 C# 解决方案也可以。
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
最佳答案
您可以查看 this使用计时器发布。
int startin = 60 - DateTime.Now.Second;
var t = new System.Threading.Timer(o => Console.WriteLine("Hello"),
null, startin * 1000, 60000);
关于c# - 在给定的时间间隔内运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1972964/