VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • Mock heartbeat via While true Thread.Sleep and System.Timers.Timer

复制代码
static void MockHeartBeatViaWhileTrue()
        {
            while (true)
            {
                Console.WriteLine($"Now is {DateTime.Now.ToString("yyyyMMddHHmmssffff")}");
                Thread.Sleep(2000);
            }
        }
复制代码
复制代码
 static void HeartBeatViaSystemTimersTimerDemo()
        {
            System.Timers.Timer heartBeatTimer = new System.Timers.Timer(2000);
            heartBeatTimer.Elapsed += HeartBeatTimerElapsed;
            heartBeatTimer.Start();

        }

        private static void HeartBeatTimerElapsed(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine($"Now is {DateTime.Now.ToString("yyyyMMddHHmmssffff")}");
        }
复制代码


相关教程