Chapter 11.

Inside the C# Class Library you have a Timer class. The Timer class is in the System.Timers namespace.

Write a program that uses this class to repeatedly write a line of text to the console at a given interval.

To do this you will need to create a handler functiom for the Elapsed event. The delegate to use to add the handler is the ElapsedEventHandler delegate.

The handler itself should have the following signature.

private void MyHandler(object sender, ElapsedEventArgs args)

using System;
using System.Timers;

namespace StopClock
{

class Class1
{

[STAThread]
static void Main(string[] args)
{

Timer myTimer = new Timer(1000);
myTimer.Elapsed +=
new ElapsedEventHandler(Writing);
myTimer.Start();
Console.ReadLine();

}

static void Writing (object source, ElapsedEventArgs e)
{

Console.WriteLine("I write this text every second");

}

}

}