-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimerControl.cs
98 lines (80 loc) · 2.53 KB
/
TimerControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
namespace StrechAlarm
{
class TimerControl
{
private System.Timers.Timer timerClock = new System.Timers.Timer();
private int clockTime = 0;
private int alarmTime = 900; // in seconds
private bool isPaused;
public TimerControl()
{
InitializeTimer();
}
void InitializeTimer()
{
timerClock.Elapsed += new ElapsedEventHandler(OnTimer);
timerClock.Interval = 1000;
timerClock.Enabled = true;
}
/// <summary>
/// Handles the Timer and calls pop-up Message Box
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void OnTimer(object sender, ElapsedEventArgs e)
{
if (!isPaused)
{
// Start the timer
try
{
this.clockTime++;
//Pop up
if (this.clockTime == this.alarmTime)
{
// When Timer is done display a pop up baloon message
using (ProcessIcon pi = new ProcessIcon())
{
pi.PopUpBaloon();
//Reset the timer so it will call again
// WARNING! This will cause it to create a bunch of message boxes if I don't stop it
ResetTimer();
}
}
}
catch (Exception ex)
{
MessageBox.Show("OnTimer(): " + ex.Message);
}
}
}
public void ResetTimer()
{
clockTime = 0;
alarmTime = 900;
// In case user clicks on Reset Timer when isPaused is true, set isPaused to false here to start timer again
isPaused = false;
}
public void PauseTimer()
{
if (!isPaused)
{
isPaused = true;
// Display message announcing timer has been paused
MessageBox.Show("See you when you get back.");
}
else
{
isPaused = false;
}
}
}
}