Exemple #1
0
        void DownloadCompletedHanlder(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);

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

                File.Move(tbPath.Text.Trim() + ".tmp", tbPath.Text.Trim());
                prgDownload.Value = 100;
                Close();
            }
            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;
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
0
 /// <summary>
 /// Handle DownloadCompleted event.
 /// </summary>
 void DownloadCompleted(object sender, DownloadCompletedEventArgs e)
 {
     this.Invoke(
         new EventHandler <DownloadCompletedEventArgs>(DownloadCompletedHanlder),
         sender, e);
 }