在运行给定的时间间隔码 [英] Run a code in given time interval

查看:101
本文介绍了在运行给定的时间间隔码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个代码,每1分钟,15分钟等难道还有比下面放了定时器控制与时间间隔1秒什么更好的办法。一个C#解决方案也行。

 如果15分钟Now.Minutemod15 = 0,那么
'运行代码
端如果
。如果Now.Minutemod1 = 0,那么
'1分钟
端运行的代码。如果


解决方案

您可以检查出的这个发布使用定时器。

  INT挑动= 60  -  DateTime.Now.Second; 
变种T =新System.Threading.Timer(O => Console.WriteLine(你好),
空,挑动* 1000,60000);


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

解决方案

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

这篇关于在运行给定的时间间隔码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆