Example #1
0
 private void Downloader_DownloadCompleted(object sender, DownloadCompletedEventArgs e)
 {
     if (e.Completed == true)
     {
         lblStatus.Text = "Status : Download Completed";
     }
     else if (e.Aborted == true)
     {
         lblStatus.Text = "Status : Download Aborted";
     }
     btnStart.Enabled = true;
     btnPauseResume.Enabled = false;
     btnPauseResume.Text = "Pause";
     btnAbort.Enabled = false;
 }
Example #2
0
 private void Download(object _StartPoint)
 {
     try
     {
         try
         {
             long _StartPointInt = Convert.ToInt64(_StartPoint);
             _WbRequest = (HttpWebRequest)WebRequest.Create(_FileURL);
             _WbRequest.AddRange(_StartPointInt);
             _WbRequest.Credentials = CredentialCache.DefaultCredentials;
             _WbResponse = (HttpWebResponse)_WbRequest.GetResponse();
             long _FileSize = _WbResponse.ContentLength;
             _StrResponse = _WbResponse.GetResponseStream();
             if (_StartPointInt == 0)
             {
                 _StrLocal = new FileStream(_FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
             }
             else
             {
                 _StrLocal = new FileStream(_FilePath, FileMode.Append, FileAccess.Write, FileShare.None);
             }
             byte[] _BufferSize = new byte[2048];
             int _BytesSize = 0;
             while ((_BytesSize = _StrResponse.Read(_BufferSize, 0, _BufferSize.Length)) > 0)
             {
                 _StrLocal.Write(_BufferSize, 0, _BytesSize);
                 UpdateProgress(_StrLocal.Length, _FileSize + _StartPointInt);
                 if (_IsPaused == true)
                 {
                     break;
                 }
             }
         }
         finally
         {
             _StrResponse.Close();
             _StrLocal.Close();
             _IsPaused = false;
             _IsRunning = false;
             _Completed = true;
             _Aborted = false;
             DownloadCompletedEventArgs NewArgs = new DownloadCompletedEventArgs(_Completed, _Aborted);
             DownloadCompleted(this, NewArgs);
         }
     }
     catch { }
 }
Example #3
0
 public void Abort()
 {
     _WbResponse.Close();
     _StrResponse.Close();
     _StrLocal.Close();
     _TmrUpdate.Stop();
     _IsPaused = false;
     _IsRunning = false;
     _Completed = false;
     _Aborted = true;
     DownloadCompletedEventArgs NewArgs = new DownloadCompletedEventArgs(_Completed, _Aborted);
     DownloadCompleted(this, NewArgs);
 }