title: How can I bring my application window to the front?
body: <p>How to bring my application window to front? For example whan my app needs attention.</p>
  
  <p>This is for my personal program. I need that functionality.</p>
  
  <p>This is what I got. But it's <strong>NOT</strong> working 100% times.</p>
  
  <pre><code>public void BringToFrontToEnterCaptha()
  {
      if (InvokeRequired)
      {
          Invoke(new Action(BringToFrontToEnterCaptha));
      }
      else
      {
          this.TopMost = true;
          this.Focus();
          this.BringToFront();
          this.textBox1.Focus();
          this.textBox1.Text = string.Empty;
          System.Media.SystemSounds.Beep.Play();
      }
  }
  
  public void BringToBackAfterEnterCaptha()
  {
      if (InvokeRequired)
      {
          Invoke(new Action(BringToBackAfterEnterCaptha));
      }
      else
      {
          this.TopMost = false;
      }
  }
  </code></pre>
  
  <p>And I call them from background worker.</p>
  
  <pre><code>BringToFrontToEnterCaptha();
  while (!ready)
  {
      Thread.Sleep(100);
  }
  BringToBackAfterEnterCaptha();
  Thread.Sleep(300);
  </code></pre>
  
  <p>And after pressing "Accept" button bool ready is set to true.</p>
  
  <p>I works great but not always. </p>