private void FileWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { string result = string.Empty; SelectedFile = null; if (e.Error != null) { result = "An error was thrown while loading PDF file(s): " + e.Error.ToString(); if (PdfFiles.Any()) { SelectedFile = PdfFiles.Last(); } } else { object[] args = (object[])e.Result; int skippedFiles = int.Parse(args[0].ToString()); int insertIndex = int.Parse(args[1].ToString()); if (PdfFiles.Any()) { if (insertIndex == -1) { SelectedFile = PdfFiles.Last(); } else if (insertIndex > 0 && insertIndex < PdfFiles.Count) { SelectedFile = PdfFiles[insertIndex - 1]; } } if (skippedFiles > 0) { result = string.Format("Due to PDF file errors, {0} PDF files could not be loaded.", skippedFiles); } } ProgressStatus = result; ProgressBarIsIndeterminate = false; IsBusy = false; }