title: How cancel Downloading Async?
body: <p>I've got a problem. How can I cancel a download ?</p>
  
  <pre><code> client.CancelAsync();
  </code></pre>
  
  <p>Doesn't work for me, because if I cancel a download and start a new one the code still tries to access the old download file. You've to know in my code is a part when a download is done it should unzip the file which has been downloaded. Example.zip like this :)
  So, when I cancel my download and start a new one you know my script tries to unzip my old Example.zip, but it should kick this .... </p>
  
  <p>For Unzipping, I'm using Iconic.Zip.dll (<a href="http://dotnetzip.codeplex.com/" rel="nofollow noreferrer">http://dotnetzip.codeplex.com/</a>)</p>
  
  <p>How to get it work?</p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>This is my Downloader Form</p>
  
  <pre><code>     private void button3_Click_1(object sender, EventArgs e)
      {
  
          DialogResult dialogResult = MessageBox.Show("This will cancel your current download ! Continue ?", "Warning !", MessageBoxButtons.YesNo);
          if (dialogResult == DialogResult.Yes)
          {
  
              cancelDownload = true;
              URageMainWindow.isDownloading = false;
              this.Close();
  
          }
          else if (dialogResult == DialogResult.No)
          {
  
          } 
      }
  </code></pre>
  
  <p>This is my Main form this happens when you start downloading something</p>
  
  <pre><code> private void checkInstall(object sender, WebBrowserDocumentCompletedEventArgs e)
      {
  
              string input = storeBrowser.Url.ToString();
  
              // Test these endings
              string[] arr = new string[]
             {"_install.html"};
  
              // Loop through and test each string
              foreach (string s in arr)
              {
                  if (input.EndsWith(s) &amp;&amp; isDownloading == false)
                  {
  
  
                     // MessageBox.Show("U.Rage is downloading your game");
                      Assembly asm = Assembly.GetCallingAssembly();
                      installID = storeBrowser.Document.GetElementById("installid").GetAttribute("value");
                     // MessageBox.Show("Name: " + installname + " ID " + installID);
                      installname = storeBrowser.Document.GetElementById("name").GetAttribute("value");
                      installurl = storeBrowser.Document.GetElementById("link").GetAttribute("value");
  
                      isDownloading = true;
                      string install_ID = installID;
                      string Install_Name = installname;
  
                      // MessageBox.Show("New Update available ! " + " - Latest version: " + updateversion + "  - Your version: " + gameVersion);
                      string url = installurl;
                      WebClient client = new WebClient();
                      client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_InstallProgressChanged);
                      client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_InstallFileCompleted);
                      client.DownloadFileAsync(new Uri(url), @"C:\U.Rage\Downloads\" + installID + "Install.zip");
                      if (Downloader.cancelDownload == true)
                      {
                          //MessageBox.Show("Downloader has been cancelled");
                          client.CancelAsync();
                          Downloader.cancelDownload = false;
                      }
                      notifyIcon1.Visible = true;
                      notifyIcon1.ShowBalloonTip(2, "Downloading !", "U.Rage is downloading " + installname, ToolTipIcon.Info);
                      System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:/U.Rage/Sounds/notify.wav");
                      player.Play();
  
                      storeBrowser.GoBack();
                      igm = new Downloader();
                      igm.labelDWGame.Text = installname;
                      // this.Hide();
                      igm.Show();
                      return;
                  }
  
                    if (input.EndsWith(s) &amp;&amp; isDownloading == true)
                  {
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:/U.Rage/Sounds/notify.wav");
                    player.Play();
                    MessageBox.Show("Please wait until your download has been finished", "Warning");
                    storeBrowser.GoBack();
                  }
              }
          }
  </code></pre>
  
  <p>This happens when the download has been finished</p>
  
  <pre><code>     void client_InstallFileCompleted(object sender, AsyncCompletedEventArgs e)
      {
          if(Downloader.cancelDownload == false)
          {
              using (ZipFile zip = ZipFile.Read(@"C:\U.Rage\Downloads\" + installID + "Install.zip"))
              {
                  //zip.Password = "iliketrains123";
                  zip.ExtractAll("C:/U.Rage/Games/", ExtractExistingFileAction.OverwriteSilently);
              }
              System.IO.File.Delete(@"C:/U.Rage/Downloads/" + installID + "Install.zip");
              notifyIcon1.Visible = true;
              notifyIcon1.ShowBalloonTip(2, "Download Completed !", "Installing was succesful !", ToolTipIcon.Info);
              System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:/U.Rage/Sounds/notify.wav");
              player.Play();
              this.Show();
              igm.Close();
              isDownloading = false;
              listView.Items.Clear();
              var files = Directory.GetFiles(@"C:\U.Rage\Games\", "*.ugi").Select(f =&gt; new ListViewItem(f)).ToArray();
              foreach (ListViewItem f in files)
              {
                  this.LoadDataFromXml(f);
              }
  
        }
      }
  </code></pre>