Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace DisplayTime
- {
- class StartUp
- {
- static void Main(string[] args)
- {
- const int frequency = 3000;
- int offset = 0;
- var DisplayTimeThread = new Thread(() =>
- {
- try
- {
- Thread.CurrentThread.IsBackground = true;
- while (true)
- {
- DisplayTime(offset);
- Thread.Sleep(frequency);
- }
- }
- catch (Exception e)
- {
- //Send a detailed message to an error handler;
- }
- });
- DisplayTimeThread.Priority = ThreadPriority.Normal;
- DisplayTimeThread.Start();
- ShowMenu();
- GetOffsetFromUser(ref offset);
- }
- private static int GetOffsetFromUser(ref int offset)
- {
- while (true)
- {
- switch (Console.ReadKey().Key)
- {
- case ConsoleKey.UpArrow:
- offset++;
- break;
- case ConsoleKey.DownArrow:
- offset--;
- break;
- case ConsoleKey.Escape:
- Environment.Exit(0);
- break;
- }
- }
- }
- static void DisplayTime(int offset)
- {
- Console.WriteLine(DateTime.UtcNow.AddHours(offset).ToString("hh:mm:ss"));
- }
- static void ShowMenu()
- {
- Console.WriteLine("Press Up to Increase by one Hour!");
- Console.WriteLine("Press Down to Decrease by one Hour!");
- Console.WriteLine("Press Esc to Exit!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment