-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (37 loc) · 974 Bytes
/
Program.cs
File metadata and controls
47 lines (37 loc) · 974 Bytes
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
using System;
using System.Media;
using System.Timers;
namespace alarmClock
{
class MainClass
{
static Timer timer;
public static void Main (string[] args)
{
Console.WriteLine ("How many seconds do you want me to beep?");
string seconds = Console.ReadLine ();
int secs;
if (int.TryParse(seconds, out secs)) {
secs*=1000;
// Create a timer with a two second interval.
timer = new System.Timers.Timer (secs);
// Hook up the Elapsed event for the timer.
timer.Elapsed += OnTimedEvent;
// Start the timer
timer.Enabled = true;
//Garbage Collector keep timer alive for eternity
GC.KeepAlive (timer);
Console.WriteLine ("Press the Enter key to exit the program at any time... ");
Console.ReadLine ();
}
else
{
Console.WriteLine ("Uh-Oh, enter a valid integer");
}
}
private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
Console.Beep ();
}
}
}