Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1.  
  2. namespace alarm
  3. {
  4. /// <summary>
  5. /// An empty page that can be used on its own or navigated to within a Frame.
  6. /// </summary>
  7. public sealed partial class MainPage : Page
  8. {
  9.  
  10. public static int min;
  11.  
  12. public MainPage()
  13. {
  14. this.InitializeComponent();
  15.  
  16. }
  17.  
  18.  
  19.  
  20.  
  21. private System.Threading.Timer timer;
  22. private void SetUpTimer(TimeSpan alertTime)
  23. {
  24.  
  25.  
  26. DateTime now = DateTime.Now;
  27.  
  28. //7 - 22:00 = -15:00 uur
  29. //7 - 10:10 = -3,10 uur
  30. //11:23 - 11:20 = 0:03
  31. //20 - 24:00 = -4 uur
  32. TimeSpan timeToGo = alertTime - now.TimeOfDay;
  33. if (timeToGo < TimeSpan.Zero)
  34. {
  35.  
  36. //22:00
  37. int t = timeToGo.Hours;
  38. t = t + 24;
  39.  
  40. System.Diagnostics.Debug.WriteLine("times has passed today calculating for tomorrow!..... uren>" + "t>" + t);
  41.  
  42. //46:00 + 24
  43. SetUpTimer(new TimeSpan(t, min, 00));
  44.  
  45. System.Diagnostics.Debug.WriteLine("times has passed today calculating for tomorrow!..... uren>" + t + "min>" + min);
  46.  
  47.  
  48. return;//time already passed
  49. }
  50.  
  51. else
  52. {
  53.  
  54. this.timer = new System.Threading.Timer(x =>
  55. {
  56. this.SomeMethodRunsAt1600();
  57. }, null, timeToGo, Timeout.InfiniteTimeSpan);
  58. }
  59. }
  60.  
  61. private void SomeMethodRunsAt1600()
  62. {
  63. System.Diagnostics.Debug.WriteLine("tut tut tut tut");
  64. timer.Dispose();
  65. }
  66.  
  67.  
  68.  
  69. private void button_Click(object sender, RoutedEventArgs e)
  70. {
  71.  
  72. int uren = int.Parse(hours.Text);
  73.  
  74. min = int.Parse(minutes.Text);
  75.  
  76. Status.Text = "Status: Alarm set " + uren + ":" + min;
  77.  
  78. SetUpTimer(new TimeSpan(uren,min, 00));
  79. System.Diagnostics.Debug.WriteLine("alarm gezet" + uren + min);
  80. }
  81.  
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement