Using a Timer with the DateTime - CSharp Language Basics

CSharp examples for Language Basics:Date Time

Description

Using a Timer with the DateTime

Demo Code

using System;// ww w  . jav  a2  s.  c  o  m
using System.Timers;
class NetTimer
{
   public static void Main()
   {
      Timer myTimer = new Timer();
      myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );
      myTimer.Interval = 1000;
      myTimer.Start();
      while ( Console.Read() != 'q' )
      {
         ;    // do nothing...
      }
   }
   public static void DisplayTimeEvent( object source, ElapsedEventArgs e )
   {
      Console.Write("\r{0}", DateTime.Now);
   }
}

Result


Related Tutorials