Esempio n. 1
0
 private void Downloader_DownloadCompleted(object sender, DownloadCompletedArg e)
 {
     this.Dispatcher.Invoke(new Action(async() =>
     {
         speedTextBlock.Text       = "0Kb/s";
         progressBar.Maximum       = 1;
         progressBar.Value         = 0;
         progressPerTextBlock.Text = "000%";
         speedValues.Clear();
         for (int i = 0; i < 49; i++)
         {
             speedValues.Add(0);
         }
         if (e.ErrorList == null || e.ErrorList.Count == 0)
         {
             await this.ShowMessageAsync(App.GetResourceString("String.Downloadwindow.DownloadComplete"),
                                         App.GetResourceString("String.Downloadwindow.DownloadComplete2"));
             this.Close();
         }
         else
         {
             await this.ShowMessageAsync(App.GetResourceString("String.Downloadwindow.DownloadCompleteWithError"),
                                         string.Format(App.GetResourceString("String.Downloadwindow.DownloadCompleteWithError2"), e.ErrorList.Count, e.ErrorList.First().Value.Message));
         }
     }));
 }
 public async Task <DownloadCompletedArg> ShowWhenDownloading()
 {
     Show();
     return(await Task.Factory.StartNew(() =>
     {
         DownloadCompletedArg completedArg = null;
         try
         {
             EventWaitHandle _waitHandle = new AutoResetEvent(false);
             App.Downloader.DownloadCompleted += (a, b) =>
             {
                 Dispatcher.Invoke(new Action(Close));
                 _waitHandle.Set();
                 completedArg = b;
             };
             _waitHandle.WaitOne();
         }
         catch (Exception ex)
         {
             AggregateExceptionArgs args = new()
             {
                 AggregateException = new(ex)
             };
             App.CatchAggregateException(this, args);
         }
         return completedArg;
     }));
 }
        private async void Downloader_DownloadCompleted(object sender, DownloadCompletedArg e)
        {
            SpeedStr        = "0Kb/s";
            ProgressMaximum = 1;
            ProgressValue   = 0;
            Percentage      = 0;
            ClearSpeedValues();
            if (e.ErrorList == null || e.ErrorList.Count == 0)
            {
                await Instance.ShowMessageAsync(this, App.GetResourceString("String.Downloadwindow.DownloadComplete"),
                                                App.GetResourceString("String.Downloadwindow.DownloadComplete2"));

                //undo close window
            }
            else
            {
                await Instance.ShowMessageAsync(this, App.GetResourceString("String.Downloadwindow.DownloadCompleteWithError"),
                                                string.Format(App.GetResourceString("String.Downloadwindow.DownloadCompleteWithError2"), e.ErrorList.Count, e.ErrorList.First().Value.Message));
            }
        }
Esempio n. 4
0
 public async Task <DownloadCompletedArg> ShowWhenDownloading()
 {
     this.Topmost = true;
     this.Show();
     return(await Task.Run(() =>
     {
         DownloadCompletedArg completedArg = null;
         try
         {
             EventWaitHandle _waitHandle = new AutoResetEvent(false);
             App.Downloader.DownloadCompleted += (a, b) =>
             {
                 this.Dispatcher.Invoke(new Action(() =>
                 {
                     try
                     {
                         this.Close();
                     }
                     catch (Exception) { }
                 }));
                 _waitHandle.Set();
                 completedArg = b;
             };
             _waitHandle.WaitOne();
         }
         catch (Exception ex)
         {
             AggregateExceptionArgs args = new AggregateExceptionArgs()
             {
                 AggregateException = new AggregateException(ex)
             };
             App.CatchAggregateException(this, args);
         }
         return completedArg;
     }));
 }