Пример #1
0
        private void InitializeSaveWorker()
        {
            if (_saveBackgroundWorker != null)
            {
                _saveBackgroundWorker.Dispose();
                _saveBackgroundWorker = null;                 // Idk if this line is even useful.
            }

            _saveBackgroundWorker = new BackgroundWorker();
            _saveBackgroundWorker.WorkerReportsProgress = true;
            _saveBackgroundWorker.DoWork += (s, e) =>
            {
                this.Invoke(() => this.MessageStatusLabel.Text   = "Saving " + Path.GetFileName(CurrentTasMovie.Filename) + "...");
                this.Invoke(() => this.SavingProgressBar.Visible = true);
                CurrentTasMovie.Save();
            };

            _saveBackgroundWorker.ProgressChanged += (s, e) =>
            {
                SavingProgressBar.Value = e.ProgressPercentage;
            };

            _saveBackgroundWorker.RunWorkerCompleted += (s, e) =>
            {
                this.Invoke(() => this.MessageStatusLabel.Text   = Path.GetFileName(CurrentTasMovie.Filename) + " saved.");
                this.Invoke(() => this.SavingProgressBar.Visible = false);

                InitializeSaveWorker();                 // Required, or it will error when trying to report progress again.
            };

            if (CurrentTasMovie != null)             // Again required. TasMovie has a separate reference.
            {
                CurrentTasMovie.NewBGWorker(_saveBackgroundWorker);
            }
        }