c#使用timer定时器
private static Timer aTimer; public void Index() { aTimer = new Timer(1000); aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); aTimer.AutoReset = true; aTimer.Enabled = true; } private static void OnTimedEvent(object source, ElapsedEventArgs e) { System.Diagnostics.Debug.WriteLine("触发的事件发生在: {0}", e.SignalTime); }
然后调用index方法即可。
参考:https://www.cnblogs.com/hdkn235/p/4187925.html
官方文档:https://docs.microsoft.com/zh-cn/dotnet/api/system.timers?redirectedfrom=MSDN&view=net-5.0