Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyViewController : UIViewController
- {
- public MyViewController(IntPtr handle)
- : base(handle)
- {
- }
- private Timer timer;
- private bool timerEventBinded;
- public override void ViewWillAppear(bool animated)
- {
- base.ViewWillAppear(animated);
- if (timer == null)
- {
- timer = new Timer();
- timer.Enabled = true;
- timer.Interval = 60000;
- }
- if (!timerEventBinded)
- {
- timer.Elapsed += OnTimedEvent;
- timerEventBinded = true;
- }
- timer.Start();
- }
- public override void ViewWillDisappear(bool animated)
- {
- if (timer != null)
- {
- timer.Stop();
- if (timerEventBinded)
- {
- timer.Elapsed -= OnTimedEvent;
- timerEventBinded = false;
- }
- }
- base.ViewWillDisappear(animated);
- }
- private void OnTimedEvent(Object src, ElapsedEventArgs e)
- {
- //do your stuff
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement