.Net Timer callback with a delegate

A timer using a delegate.

using System;
using System.Threading;

namespace TimerCallbacks
{
    class Program
    {
        static void Main(string[] args)
        {
            var tb = new TimerCallback(PrintTime);

            var t = new Timer(tb,
               null,
               0,
               1000
            );

            Console.ReadKey();

        }

        static void PrintTime(object state)
        {
            Console.WriteLine("{0}", DateTime.Now.ToLocalTime());
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *