Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. Console.WriteLine("Aktualny czas: {0}", DateTime.Now);
  6. new Alarm(10);
  7.  
  8. Console.ReadKey();
  9. }
  10. }
  11.  
  12. class Alarm
  13. {
  14. private DateTime _time;
  15. private Timer _alarm;
  16.  
  17. public Alarm(int seconds)
  18. {
  19. _time = DateTime.Now.AddSeconds(seconds);
  20.  
  21. _alarm = new Timer(1000);
  22. _alarm.Elapsed += new ElapsedEventHandler(checkAlarmTime);
  23. _alarm.Enabled = true;
  24.  
  25. Console.WriteLine("Alarm został ustawiony na : {0}", this._time);
  26. }
  27.  
  28. public int SetTime
  29. {
  30. set
  31. {
  32. this._time = DateTime.Now.AddSeconds(value);
  33. }
  34. }
  35.  
  36. public DateTime GetTime
  37. {
  38. get
  39. {
  40. return this._time;
  41. }
  42. }
  43.  
  44. private void checkAlarmTime(object sender, ElapsedEventArgs e) {
  45. if (e.SignalTime >= this._time)
  46. {
  47. Console.WriteLine("\n Alarm {0}", e.SignalTime);
  48. _alarm.Enabled = false;
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement