Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace alarm
- {
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- public sealed partial class MainPage : Page
- {
- public static int min;
- public MainPage()
- {
- this.InitializeComponent();
- }
- private System.Threading.Timer timer;
- private void SetUpTimer(TimeSpan alertTime)
- {
- DateTime now = DateTime.Now;
- //7 - 22:00 = -15:00 uur
- //7 - 10:10 = -3,10 uur
- //11:23 - 11:20 = 0:03
- //20 - 24:00 = -4 uur
- TimeSpan timeToGo = alertTime - now.TimeOfDay;
- if (timeToGo < TimeSpan.Zero)
- {
- //22:00
- int t = timeToGo.Hours;
- t = t + 24;
- System.Diagnostics.Debug.WriteLine("times has passed today calculating for tomorrow!..... uren>" + "t>" + t);
- //46:00 + 24
- SetUpTimer(new TimeSpan(t, min, 00));
- System.Diagnostics.Debug.WriteLine("times has passed today calculating for tomorrow!..... uren>" + t + "min>" + min);
- return;//time already passed
- }
- else
- {
- this.timer = new System.Threading.Timer(x =>
- {
- this.SomeMethodRunsAt1600();
- }, null, timeToGo, Timeout.InfiniteTimeSpan);
- }
- }
- private void SomeMethodRunsAt1600()
- {
- System.Diagnostics.Debug.WriteLine("tut tut tut tut");
- timer.Dispose();
- }
- private void button_Click(object sender, RoutedEventArgs e)
- {
- int uren = int.Parse(hours.Text);
- min = int.Parse(minutes.Text);
- Status.Text = "Status: Alarm set " + uren + ":" + min;
- SetUpTimer(new TimeSpan(uren,min, 00));
- System.Diagnostics.Debug.WriteLine("alarm gezet" + uren + min);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement