title: C# windows application not closing
body: <p>my post is same like <a href="https://stackoverflow.com/questions/465306/c-windows-application-not-closing">This</a>... but that post didn't solve'd my question, so my question is.</p>
  
  <p>m building a win app in c#, and in that im using <code>backgroundworkder thread</code> and <code>Application.DoEvents</code>. here's my code:</p>
  
  <pre><code>for(int i=0;i&lt;gridview.rows.count-1;i++)
  {
    if (backThread.CancellationPending)
              {
                  e.Cancel = true;
                  break;
              }
          string TargetFrame = "";
          byte[] vPost = ASCIIEncoding.ASCII.GetBytes("_PostData");
          string Header = "Content-Type: application/x-www-form-urlencoded" + "\n" + "\r";
          autoWebPage.Navigate("https://xyz.com", TargetFrame, vPost, Header);
          while (car == false)
          {
              System.Threading.Thread.Sleep(500);
              Application.DoEvents();
          }
  }
  </code></pre>
  
  <p>and this loop is under <code>BackGroundWorker_DoWork()</code> event, The Problem is m not able to close the form or application, i.e in taskmanager my app is still running, i dn't know what is the cause, maybe <code>Application.DoEvents</code> or <code>BackGroundWorker thread</code>, i google'd about this issue, but i didn't get any clear idea.. i tried to close the form using this:</p>
  
  <pre><code>//Application.Exit();
  //mainmdiForm.Dispose();
  //mainmdiForm.Close();
  //backGroundWorker.CancelAsync();
  </code></pre>
  
  <p>but no success. And one more thing while searchin' about this issue on google,, i got many results sayin' <code>Application.DoEvents()</code> is an EVIL, m curious why is that so ?</p>