private void _backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     _cancellationPending = _dialog.HasUserCancelled();
     // ReportProgress doesn't allow values outside this range. However, CancellationPending will call
     // BackgroundWorker.ReportProgress directly with a value that is outside this range to update the value of the property.
     if (e.ProgressPercentage >= 0 && e.ProgressPercentage <= 100)
     {
         _dialog.SetProgress((uint)e.ProgressPercentage, 100);
         ProgressChangedData data = e.UserState as ProgressChangedData;
         if (data != null)
         {
             if (data.Text != null)
             {
                 Text = data.Text;
             }
             if (data.Description != null)
             {
                 Description = data.Description;
             }
             if (data.Expanded != null)
             {
                 Expanded = data.Expanded;
             }
             OnProgressChanged(new ProgressChangedEventArgs(e.ProgressPercentage, data.UserState));
         }
     }
 }
        private void _backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            var cancellationTokenSource = _cancellationTokenSource;

            var cancellationRequestedByUser = _dialog.HasUserCancelled();
            var cancellationRequestedByCode = cancellationTokenSource?.IsCancellationRequested ?? false;

            if (cancellationRequestedByUser && !cancellationRequestedByCode)
            {
                cancellationTokenSource.Cancel();
            }

            _cancellationPending = cancellationRequestedByUser || cancellationRequestedByCode;

            // ReportProgress doesn't allow values outside this range. However, CancellationPending will call
            // BackgroundWorker.ReportProgress directly with a value that is outside this range to update the value of the property.
            if (e.ProgressPercentage >= 0 && e.ProgressPercentage <= 100)
            {
                _dialog.SetProgress((uint)e.ProgressPercentage, 100);
                ProgressChangedData data = e.UserState as ProgressChangedData;
                if (data != null)
                {
                    if (data.Text != null)
                    {
                        Text = data.Text;
                    }
                    if (data.Description != null)
                    {
                        Description = data.Description;
                    }
                    OnProgressChanged(new ProgressChangedEventArgs(e.ProgressPercentage, data.UserState));
                }
            }
        }