title: How do I stop an Application DoEvents loop in C++?
body: <p>This is a Visual Studio Express C++ Windows Forms application.</p>
  
  <p>I want to play a WAV file strFileName.WAV in a WAV play wavPlayer every 10 seconds from the time I press the "Start" button until such time as I press the "Stop" button.</p>
  
  <p>When each 10 second interval is up, TimerEventProcessor plays the WAV file.</p>
  
  <p>The problem is that I have to press "Stop" twice to get it to work. The first press of "Stop" seems to be ignored.</p>
  
  <p>Why is btnStop_Click not executing the first time I press "Stop"?</p>
  
  <pre><code>private: System::Void bntStart_Click(System::Object^  sender, System::EventArgs^  e) {
    if (String::IsNullOrEmpty(strFileName)) {
      lblRunning-&gt;Text = L"Cannot Start Until File Is Loaded";
    }
    else {
      lblRunning-&gt;Text = L"Running";   
      myTimer-&gt;Interval = iIntervalSeconds * 1000;
      myTimer-&gt;Tick += gcnew EventHandler( TimerEventProcessor );
      myTimer-&gt;Enabled = true;
      while (lblRunning-&gt;Text == L"Running") {
        Application::DoEvents();
      }
    }
  }
  
  private: System::Void btnStop_Click(System::Object^  sender, System::EventArgs^  e) {
    lblRunning-&gt;Text = L"Stopped";
    myTimer-&gt;Enabled = false;
    wavPlayer-&gt;Stop();
  }
  </code></pre>