在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
包含Timer类的命名空间有3个 Timer Class (System.Threading) Timer Class (System.Windows.Forms) 一般用于窗体程序
using System;
class Program { public static void Main() { Timer t = new System.Timers.Timer(1000); t.Interval = 2000; //t.AutoReset = false; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true) t.Enabled = true; //是否触发Elapsed事件 t.Elapsed += new ElapsedEventHandler(t_Elapsed); Console.WriteLine("Press the Enter key to exit the program."); //从标准输入流读取下一行 Console.ReadLine(); // Keep the timer alive until the end of Main. GC.KeepAlive(t); } static void t_Elapsed(object sender, ElapsedEventArgs e) { Console.WriteLine("hello world!!"); } }
using System.Web.UI; 此时前端代码.aspx <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server"> </asp:Timer> </div> </form> </body>
|
请发表评论