Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class App
- {
- public delegate void StopHandler();
- public event StopHandler OnStop;
- private bool keepAlive = true;
- public App()
- {
- OnStop += (() => { keepAlive = false; });
- new Thread(() => CheckForStop()).Start();
- new Thread(() => Update()).Start();
- while (keepAlive) { }
- }
- private void CheckForStop()
- {
- while (keepAlive) if (Console.ReadKey().Key.Equals(ConsoleKey.Enter)) OnStop();
- }
- private void Update()
- {
- int counter = 0;
- while (keepAlive)
- {
- counter++;
- Console.WriteLine(string.Format("[{0}] Update #{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), counter));
- Thread.Sleep(3000);
- }
- }
- }
Add Comment
Please, Sign In to add comment