using System.Timers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public delegate void MessageHandler(string messageText);
class Program
{
static void Main(string[] args)
{
Connection myConnection = new Connection();
myConnection.MessageArrived += new MessageHandler(DisplayMessage);
}
public static void DisplayMessage(string message)
{
Console.WriteLine(message);
}
}
public class Connection
{
public event MessageHandler MessageArrived;
private Timer pollTimer;
public Connection()
{
pollTimer = new Timer(100);
pollTimer.Elapsed += new ElapsedEventHandler(CheckForMessage);
pollTimer.Start();
}
private static Random random = new Random();
private void CheckForMessage(object source, ElapsedEventArgs e)
{
if (MessageArrived == null)
{
MessageArrived("Hello Mum!");
}
}
}