using System.Collections.Generic;
private static List<Alarms> Timers = new List<Alarms>();
private static string menu = "1) Create Timer" +
"\n4) Change name of Timer";
static void Main(string[] args)
_ = Timers.RemoveAll(p => p.Done == true);
while (Console.KeyAvailable)
Alarms.MenuSwitch(Console.ReadKey(true), Timers);
public string Message { get; private set; }
public uint Duration { get; private set; }
public static System.Timers.Timer aTimer = new System.Timers.Timer();
public SpeechSynthesizer synthesizer = new SpeechSynthesizer();
public bool Done { get; private set; }
DateTime begin = DateTime.Now;
public Alarms(uint duration, string name, string message)
synthesizer.SetOutputToDefaultAudioDevice();
aTimer.Interval = duration;
aTimer.Elapsed += Finished;
aTimer.AutoReset = false;
public Alarms(uint duration, string name) : this(duration, name, "") { }
public void Finished(object source, System.Timers.ElapsedEventArgs e)
if (Message.Trim() == "")
synthesizer.SpeakAsync(Name);
synthesizer.SpeakAsync(Message);
public override string ToString()
return $"Timer {Name}: {DateTime.Now - begin} seconds elapsed of {Duration / 1000} seconds";
public static void MenuSwitch(ConsoleKeyInfo key, List<Alarms> list)
Console.WriteLine("How long is the timer in seconds?");
while (!UInt32.TryParse(Console.ReadLine(), out time)) ;
Console.WriteLine("What's the name of timer?");
name = Console.ReadLine();
Console.WriteLine("Does the timer have a message? y/n");
if (Console.ReadKey(true).Key == ConsoleKey.Y)
Console.WriteLine("Please input a message");
list.Add(new Alarms(time * 1000, name, Console.ReadLine()));
Console.WriteLine("Timer successfully created");
Console.WriteLine("Timer successfully created");
list.Add(new Alarms(time * 1000, name));
list.ForEach(x => Console.WriteLine(x));
Console.WriteLine("Which timer would you like to remove? (name of timer)");
name = Console.ReadLine();
list.RemoveAll(p => p.Name == name);
Console.WriteLine("Please enter the name of the object you would like to change the name of");
name = Console.ReadLine();
int temp = list.IndexOf(list.Find(p => p.Name == name));
Console.WriteLine("Invalid");
Console.WriteLine("Enter new name");
list.ElementAt(temp).Name = Console.ReadLine();