Console Application for calling Event using System.Timers in C# 1.1 and 2.0 (Dot Net)

Google+ Pinterest LinkedIn Tumblr +

using System;

using System.Timers;

namespace evnt1

{

class Class1

{

static int count=0;

static string dispstrg=”How are you “;

public static void Main()

{

Timer mt=new Timer(100);

mt.Elapsed+=new ElapsedEventHandler(mt_Elapsed);

mt.Start();

Console.ReadLine();

method m=new method();

m.mt1.Elapsed+=new ElapsedEventHandler(m.show);

m.mt1.Start();

Console.ReadLine();

}

private static void mt_Elapsed(object sender, ElapsedEventArgs e)

{

if(count<dispstrg.length> Console.Write(dispstrg[count++ %dispstrg.Length]);

}

}

public class method

{

public Timer mt1=new Timer(250);

public void show(object sender, ElapsedEventArgs e)

{

Console.WriteLine(“Do you find that amusing”);

mt1.Stop();

}

}

</dispstrg.length></p>

Share.

About Author

Leave A Reply