title: How do I wait to Timer finish and then return from function?
body: <p>I want to wait to a timer finish and then return from a function. I tried this:</p>
  
  <pre><code>while(timer1.Enabled)
  {
      Application.DoEvents();
  }
  return value;
  </code></pre>
  
  <p>But it didn't work and the function returned before the timer really finished. Here's the full function:</p>
  
  <pre><code>System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
  int[] foo()
  {
  
      do_something1();
  
      int[] some_value;
  
      timer1.Interval = 1000;
      timer1.Tick += new EventHandler(delegate(object o, EventArgs ea)
      {
          if (browser.ReadyState == WebBrowserReadyState.Complete)
          {
              timer1.Stop();
              baa(some_value);
          }
      });
      timer1.Start();
  
      while (timer1.Enabled)
      {
          Application.DoEvents();
      }
  
      return some_value;
  }
  </code></pre>