How do i slow down event,so the output would look like this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
namespace Event1
{
public delegate void DingDongHandler(string text);
public class ClassWithEvent
{
public Timer DingdongTimer { get; private set; }
public event DingDongHandler DingDong;
public void Start()
{ //this code just uses the Timer object which will at some
//point cause the method CheckTimer to be called
DingdongTimer = new Timer(2000);
DingdongTimer.Elapsed += CheckTimer;
DingdongTimer.Start();
}
public void CheckTimer(object source, ElapsedEventArgs e)
{ //this raises the event DingDong
DingDong("Dinnnng Donnnnnng"); ;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Event1
{
class Program
{
static void Main(string[] args)
{
var obj = new ClassWithEvent();
//subscribe to the event
obj.DingDong += MyEhMethod;
//use the object which may raise an event
obj.Start();
Console.WriteLine( "Enter first number:" );
int first = int.Parse(Console.ReadLine( ));
Console.WriteLine( "Enter second number :" );
int second = int.Parse(Console.ReadLine());
int result = first + second;
Console.WriteLine( "Result is" +result );
Console.Read();
}
static public void MyEhMethod(string text)
{
Console.WriteLine("Have received {0} ", text);
}
}
}