Guest User

Untitled

a guest
Mar 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class App
  2. {
  3. public delegate void StopHandler();
  4. public event StopHandler OnStop;
  5.  
  6. private bool keepAlive = true;
  7.  
  8. public App()
  9. {
  10. OnStop += (() => { keepAlive = false; });
  11.  
  12. new Thread(() => CheckForStop()).Start();
  13. new Thread(() => Update()).Start();
  14.  
  15. while (keepAlive) { }
  16. }
  17.  
  18. private void CheckForStop()
  19. {
  20. while (keepAlive) if (Console.ReadKey().Key.Equals(ConsoleKey.Enter)) OnStop();
  21. }
  22.  
  23. private void Update()
  24. {
  25. int counter = 0;
  26.  
  27. while (keepAlive)
  28. {
  29. counter++;
  30.  
  31. Console.WriteLine(string.Format("[{0}] Update #{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), counter));
  32.  
  33. Thread.Sleep(3000);
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment