Saturday, 2 December 2017

C# Program to Illustrate Elapsed Event


Code:

using System;
using System.Timers;
public class Program
{
    private static System.Timers.Timer Tim;
    public static void Main()
    {
        Tim = new System.Timers.Timer(10);
        Tim.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        Tim.Interval = 1000;
        Tim.Enabled = true;
        Console.WriteLine("Press Any Key to Exit else Elapsed Event will be Raised ");
        Console.ReadLine();
    }
    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        Console.WriteLine("The Elapsed event was Raised {0}", e.SignalTime);
    }
}


Output:

Press Any Key to Exit else Elapsed Event will be Raised :
The Elapsed event was raised at 9/17/2013 7:24:15 PM
The Elapsed event was raised at 9/17/2013 7:24:16 PM
The Elapsed event was raised at 9/17/2013 7:24:17 PM


More C# Programs:



















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...