void DownloadCompletedHandler(object sender, DownloadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                lbSummary.Text =
                    String.Format("Received: {0}KB, Total: {1}KB, Time: {2}:{3}:{4}",
                                  e.DownloadedSize / 1024, e.TotalSize / 1024, e.TotalTime.Hours,
                                  e.TotalTime.Minutes, e.TotalTime.Seconds);

                File.Move(tbPath.Text.Trim() + ".tmp", tbPath.Text.Trim());

                prgDownload.Value = 100;
            }
            else
            {
                lbSummary.Text = e.Error.Message;
                if (File.Exists(tbPath.Text.Trim() + ".tmp"))
                {
                    File.Delete(tbPath.Text.Trim() + ".tmp");
                }

                if (File.Exists(tbPath.Text.Trim()))
                {
                    File.Delete(tbPath.Text.Trim());
                }

                prgDownload.Value = 0;
            }
        }
Пример #2
0
 /// <summary>
 /// Raise DownloadCompleted event.
 /// </summary>
 protected virtual void OnDownloadCompleted(
     DownloadCompletedEventArgs e)
 {
     if (DownloadCompleted != null)
     {
         DownloadCompleted(this, e);
     }
 }
Пример #3
0
        /// <summary>
        /// The method will be called by the OnStatusChanged method.
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnDownloadCompleted(DownloadCompletedEventArgs e)
        {
            if (e.Error != null && this.status != DownloadStatus.Canceled)
            {
                this.Status = DownloadStatus.Completed;
            }

            if (DownloadCompleted != null)
            {
                DownloadCompleted(this, e);
            }
        }
Пример #4
0
 /// <summary>
 /// Handle the DownloadCompleted event of all the HttpDownloadClients.
 /// </summary>
 void client_DownloadCompleted(object sender, DownloadCompletedEventArgs e)
 {
     if (e.Error != null &&
         this.Status != DownloadStatus.Canceling &&
         this.Status != DownloadStatus.Canceled)
     {
         this.Cancel();
         this.OnDownloadCompleted(new DownloadCompletedEventArgs(
                                      null,
                                      this.DownloadedSize,
                                      this.TotalSize,
                                      this.TotalUsedTime,
                                      e.Error));
     }
 }
 /// <summary>
 /// Handle DownloadCompleted event.
 /// </summary>
 void DownloadCompleted(object sender, DownloadCompletedEventArgs e)
 {
     this.Invoke(
         new EventHandler <DownloadCompletedEventArgs>(DownloadCompletedHandler),
         sender, e);
 }