Skip to content

Instantly share code, notes, and snippets.

@fiyazbinhasan
Created October 28, 2017 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiyazbinhasan/5a9e0e8af6ca497724f5a14adecb8749 to your computer and use it in GitHub Desktop.
Save fiyazbinhasan/5a9e0e8af6ca497724f5a14adecb8749 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace MysteryOfDelegates
{
public class Clock
{
public DateTime Alarm { get; set; }
}
public delegate void ClockAlarm(Clock clock, string name);
class Program
{
static void Main(string[] args)
{
var clock = new Clock();
clock.Alarm = DateTime.Now.AddSeconds(5);
ClockAlarm clockAlarm;
clockAlarm = Wakeup;
}
private static void Wakeup(Clock clock, string name)
{
while (true)
{
Thread.Sleep(1000);
DateTime currentTime = DateTime.Now;
if (currentTime.Second == clock.Alarm.Second)
{
Console.WriteLine(name + ", " + "Please wake up!!!!");
break;
}
Console.WriteLine("Clock is ticking!!!");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment