static void Main(string[] args) { // //AddInventory(); System.Timers.Timer timer = new System.Timers.Timer(); timer.Enabled = true; timer.Interval = 60000; timer.Start(); timer.Elapsed += new System.Timers.ElapsedEventHandler(T_Elapsed); Console.Read(); } private static void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { int intHour = e.SignalTime.Hour; int intMinute = e.SignalTime.Minute; // int intSecond = e.SignalTime.Second; //定制刷新库的时间 int iHour = Convert.ToInt32(ConfigurationManager.AppSettings["Hours"].ToString()); int iMinute = Convert.ToInt32(ConfigurationManager.AppSettings["Mininus"].ToString()); // int iSecond = 00; if (intHour == iHour && intMinute == iMinute) { AddInventory(); } }
实现每隔一分钟执行一次,当发现当前时间与设置的时间一样时,自动执行需要执行的方法,适合每天需要定时执行一遍的需求