Advertisement
hristo_bratanov

Show message using timer

Mar 2nd, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1.     using System;
  2.     using System.Diagnostics;
  3.     using System.Linq;
  4.  
  5.     public class Timer
  6.     {
  7.         static void Main()
  8.         {
  9.             int interval = Int32.Parse(Console.ReadLine());
  10.             Stopwatch sw = new Stopwatch();
  11.             sw.Start();
  12.             Func<int, bool> sleep = (x) =>
  13.             {
  14.                 if (x * 1000 == sw.ElapsedMilliseconds)
  15.                     return true;
  16.                 else
  17.                     return false;
  18.             };
  19.             while (true)
  20.             {
  21.                 if (sleep(interval) == true)
  22.                 {
  23.                     Console.WriteLine("surprise");
  24.                     sw.Restart();
  25.                 }
  26.             }
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement