双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

定时器代码没错误但不运行

ccbbcc CSDN会员 ccbbcc 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

代码:

using System;
using System.Timers;

class Program
{
    private static Timer aTimer;
    private static int counter = 0;

    static void Main(string[] args)
    {
        // 创建一个定时器,设置时间间隔为1000毫秒(1秒)  
        aTimer = new Timer(1000);

        // 绑定事件处理方法  
        aTimer.Elapsed += OnTimedEvent;

        // 设置是否重复触发  
        aTimer.AutoReset = true;

        // 启动定时器  
        aTimer.Enabled = true;

        Console.WriteLine("Press the Enter key to exit the program.");
        Console.ReadLine();
    }

    private static void OnTimedEvent(Object source, ElapsedEventArgs e)
    {
        // 在这里编写定时执行的代码  
        counter++;
        Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}", e.SignalTime);
        Console.WriteLine("Counter: " + counter);
    }
}

 请问专家,为什么没有输出?谢谢

 

...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
ccbbcc CSDN会员
C# 111,129 成员 642,540 内容