Пример #1
0
        private void btnInstall_Click(object sender, RoutedEventArgs e)
        {
            var worker = new BackgroundWorker {
                WorkerReportsProgress = true
            };

            worker.DoWork          += (x, y) => _dbManager.AddAddon(y.Argument as string, worker);
            worker.ProgressChanged += (x, y) =>
            {
                Pb1.Visibility     = Visibility.Visible;
                Spinner.Visibility = Visibility.Visible;
                Pb1.Value         += y.ProgressPercentage;
            };
            worker.RunWorkerCompleted += (x, y) => { _mainWindow.UpdateListBoxOnMainWindow(); Close(); };

            worker.RunWorkerAsync(_downloadUrlRegex.Match(TxtUrl.Text).Value);
        }
Пример #2
0
        private void imgUpdate_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var addonViewModel = (sender as Image)?.DataContext as AddonViewModel;

            var worker = new BackgroundWorker {
                WorkerReportsProgress = true
            };

            worker.DoWork += (x, y) =>
            {
                (x as BackgroundWorker)?.ReportProgress(0);
                if (addonViewModel != null)
                {
                    _dbManager.RemoveAddon(addonViewModel.Addon.Id);
                    _dbManager.AddAddon(addonViewModel.Addon.DownloadUrl, worker);
                }
            };

            worker.ProgressChanged += (x, y) =>
            {
                if (addonViewModel != null && addonViewModel.UpdateCogVisibility != Visibility.Visible)
                {
                    addonViewModel.UpdateCogVisibility = Visibility.Visible;
                    LblAddonList.Items.Refresh();
                }
            };

            worker.RunWorkerCompleted += (o, args) =>
            {
                if (addonViewModel != null)
                {
                    File.Delete(addonViewModel.Addon.ImagePath);
                }
                if (addonViewModel != null)
                {
                    addonViewModel.UpdateCogVisibility = Visibility.Collapsed;
                }
                UpdateListBoxOnMainWindow();
            };

            worker.RunWorkerAsync();
        }