SHARE
TWEET

Untitled

a guest Mar 15th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Timer actualTimer = new Timer(obj => Console.WriteLine("Timer!"),
  2.     null, 0, 1000);
  3.  
  4. Timer killingTimer = new Timer(obj =>
  5. {
  6.     Console.WriteLine("Killing timer!");
  7.     // Set the dueTime and timeout to infinite, to stop the timer.
  8.     actualTimer.Change(Timeout.Infinite, Timeout.Infinite);
  9.     killingTimer.Change(Timeout.Infinite, Timeout.Infinite);
  10. }, null, 5000, 5000);
  11.  
  12. Console.ReadLine();
  13.    
  14. Timer actualTimer = new Timer();
  15. actualTimer.Interval = 1000;
  16. actualTimer.Elapsed += (sender, e) => Console.WriteLine("Timer!");
  17. actualTimer.Start();
  18.  
  19. Timer killingTimer = new Timer();
  20. killingTimer.Interval = 5000;
  21. killingTimer.Elapsed += (sender, e) =>
  22. {
  23.     Console.WriteLine("Killing timer!");
  24.     actualTimer.Stop();
  25.     killingTimer.Stop();
  26. };
  27. killingTimer.Start();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top