private static void Timekeeping(int expire) { System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = expire; timer.Enabled = true; timer.AutoReset = false; timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent); timer.Start(); } private static void OnTimedEvent(object source, ElapsedEventArgs e) { if (Login() == false) { Process.GetCurrentProcess().CloseMainWindow(); Process.GetCurrentProcess().Kill(); Log.WriteLog("登录", "程序加载", "登录API失败,获取token失败,关闭程序"); } }
//如果将 System.Timers.Timer timer = new System.Timers.Timer();设置为全局变量的话,会出现循环执行,但是没有间隔时间