Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. class MyViewController : UIViewController
  2. {
  3. public MyViewController(IntPtr handle)
  4. : base(handle)
  5. {
  6. }
  7.  
  8. private Timer timer;
  9. private bool timerEventBinded;
  10.  
  11. public override void ViewWillAppear(bool animated)
  12. {
  13. base.ViewWillAppear(animated);
  14. if (timer == null)
  15. {
  16. timer = new Timer();
  17. timer.Enabled = true;
  18. timer.Interval = 60000;
  19. }
  20.  
  21. if (!timerEventBinded)
  22. {
  23. timer.Elapsed += OnTimedEvent;
  24. timerEventBinded = true;
  25. }
  26.  
  27. timer.Start();
  28. }
  29.  
  30. public override void ViewWillDisappear(bool animated)
  31. {
  32. if (timer != null)
  33. {
  34. timer.Stop();
  35. if (timerEventBinded)
  36. {
  37. timer.Elapsed -= OnTimedEvent;
  38. timerEventBinded = false;
  39. }
  40. }
  41.  
  42. base.ViewWillDisappear(animated);
  43. }
  44.  
  45. private void OnTimedEvent(Object src, ElapsedEventArgs e)
  46. {
  47. //do your stuff
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement