title: Xamarin.ios - Timer not executing actions after time
body: <p>I am currently making a little game in Xamarin.ios and the idea is that you have 30 seconds from the time you press start until its over (and takes you to the game over screen) but if you do the wrong move then its also game over. I am using System.Timers and the timer starts fine and begins ticking but when you get to 30 seconds and it stops, it prints to the console that the timer has finished but then doesn't do anything I want it to. I have tried everything I can think of but can't seem to figure it out. Any help is appreciated, thank you! Also sorry in advance, this is my first time using stackoverflow.</p>
  
  <p>Here is the main code:</p>
  
  <pre><code>    //Setting up the timer
      int count = 1;
      System.Timers.Timer timer1;
  
      private void OnTimeEvent(object source, ElapsedEventArgs e)
      {
          count++;
          Console.WriteLine ("timer tick");
          if (count == 30)
          {
              timer1.Enabled = false;
              Console.WriteLine ("timer finished");
  
              //**Everything from here on is just what I want to happen**
              imgBackground.Image = UIImage.FromFile ("gameover.jpg");
              btn1.SetBackgroundImage (null, UIControlState.Normal);
              btn2.SetBackgroundImage (null, UIControlState.Normal);
              btn3.SetBackgroundImage (null, UIControlState.Normal);
              btn4.SetBackgroundImage (null, UIControlState.Normal);
              lblTime.Text = "";
              btnStart.Enabled = true;
              hasend = true;
              //score is set back to 0
              score = 0;
              btn1green = false;
              btn2green = false;
              btn3green = false;
              btn4green = false;
          }
      }
  </code></pre>
  
  <p>Here is what I have on the start button (which works fine)</p>
  
  <pre><code>    //Start the timer
      timer1.Enabled = true;
      Console.WriteLine("timer started");
  </code></pre>
  
  <p>And here is what I have when you make a wrong move (also works fine)</p>
  
  <pre><code>        else
          {
              //adjust the UI
              imgBackground.Image = UIImage.FromFile("gameover.jpg");
              btn1.SetBackgroundImage(null, UIControlState.Normal);
              btn2.SetBackgroundImage(null, UIControlState.Normal);
              btn3.SetBackgroundImage(null, UIControlState.Normal);
              btn4.SetBackgroundImage(null, UIControlState.Normal);
              lblTime.Text = "";
              btnStart.Enabled = true;
              hasend = true;
              //score is set back to 0
              score = 0;
              btn1green = false;
              btn2green = false;
              btn3green = false;
              btn4green = false;
              timer1.Enabled = false;
              Console.WriteLine("timer stopped");
          }
  </code></pre>
  
  <p>So as you can see that is a decent amount to change in the UI once the timer finishes. I think that might have something to do with why it's not working</p>
  
  <p>EDIT: This is also where I set up the timer under ViewDidLoad ()</p>
  
  <pre><code>timer1 = new System.Timers.Timer();
  timer1.Interval = 1000;
  timer1.Elapsed += new ElapsedEventHandler(OnTimeEvent);
  </code></pre>