public static void BackgroundWorkerReportProgress(long progress, long total, BackgroundWorker backgroundWorker) { try { NullChecks.BackgroundWorkers(backgroundWorker); int percentage = (int)Math.Round((double)((double)progress / total) * 100); // Prevent unnecessary calls if (percentage != 0 && percentage != _previousPercentage) { backgroundWorker.ReportProgress(percentage); } _previousPercentage = percentage; } catch (Exception ex) when(ExceptionFilters.ReportProgressExceptions(ex)) { Logging.LogException(ex.ToString(), Logging.Severity.Bug); DisplayMessage.ErrorResultsText(string.Empty, ex.GetType().Name, "Background worker report progress exception. This is a bug - please report it."); } }