public class TimerDemo
{
public void Start()
{
/// <summary>
/// 定时器
/// </summary>
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += new ElapsedEventHandler(TimeEvent);
//触发的时间间隔 此处设置为10秒
timer.Interval = 10000;
timer.Enabled = true;
}
private void TimeEvent(object source, ElapsedEventArgs e)
{
console.log("这句话会被定时器一直循环打印");
}
}
在主程序页面只需实例化,然后调用start()方法,它就会定时执行。
TimerDemo demo = new TimerDemo();
demo .Start();
C#服务器端实现定时器功能
最新推荐文章于 2023-08-04 11:59:51 发布
该博客主要围绕C#服务器端展开,核心内容是实现定时器功能,在信息技术领域,这有助于服务器端进行定时任务的管理和执行。
395

被折叠的 条评论
为什么被折叠?



