Created
October 28, 2017 05:27
-
-
Save fiyazbinhasan/5a9e0e8af6ca497724f5a14adecb8749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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