Ejemplo n.º 1
0
        public bool Run(List<Archive> archives)
        {
            var updater = new Updater(archives);

            var worker = new BackgroundWorker();
            worker.WorkerReportsProgress = true;
            worker.ProgressChanged += (object sender, ProgressChangedEventArgs e) => {
                _progressBar.Value = e.ProgressPercentage;
                _status.Text = e.UserState as string;
                this.Refresh();
            };

            updater.StatusChanged += (object sender, UpdaterEventArgs e) => {
                worker.ReportProgress(e.progress, e.status);
            };

            worker.DoWork += (object sender, DoWorkEventArgs e) => {
                updater.Run();
            };

            worker.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) => {
                this._launchButton.Enabled = true;

                if (_autoLaunch.Checked) {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            };

            worker.RunWorkerAsync();

            return ShowDialog() == DialogResult.OK;
        }