private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                labelStatus.Text           = "Canceled .... The processing is incomplete.";
                progressBarConvert.Value   = 0;
                progressBarConvert.Visible = false;
                ReportOnCancel();
            }
            else if (e.Error != null)
            {
                MessageBox.Show("Error. Details: " + (e.Error as Exception).ToString());
                progressBarConvert.Value   = 0;
                progressBarConvert.Visible = false;
            }
            else
            {
                thisBackWrkARgs thisArg = e.Result as thisBackWrkARgs;
                progressBarConvert.Visible = true;
                progressBarConvert.Value   = progressBarConvert.Maximum;
                labelStatus.Text           = "Done Creating PDF cut splits";
                labelStatus.Font           = new Font(labelStatus.Font, FontStyle.Bold);
                string _PDFname = Path.GetFileNameWithoutExtension(listViewSourcePDFs.CheckedItems[listViewSourcePDFs.CheckedItems.Count - 1].SubItems[0].Text.ToLower());
                int    cnt      = QtyOfJPGS(_PDFname, currentTargetFolder);
                if (!listViewSourcePDFs.CheckedItems[listViewSourcePDFs.CheckedItems.Count - 1].SubItems[1].Text.Equals(msgFileMissing))
                {
                    listViewSourcePDFs.CheckedItems[listViewSourcePDFs.CheckedItems.Count - 1].SubItems[1].Text = msgProcessedInto + Convert.ToString(cnt) + " " + msgOutPutType;
                }
            }



            /// The problem solved by this is that the progress bar needs to reach 100% and then go away
            /// by itself. There is an animation delay going on in that that bar step to 100% but the
            /// progressbar visible command closes out the bar before that animation duration gets anywhere.
            /// This results in no progress shown for the last step.  A sleep thread does
            /// not work because the progress bar animation up to that 100% sleeps in the same thread.
            if (progressBarConvert.Value == progressBarConvert.Maximum)
            {
                DateTime Tthen = DateTime.Now;
                do
                {
                    Application.DoEvents();
                } while (Tthen.AddSeconds(1) > DateTime.Now);
                progressBarConvert.Visible = false;
            }

            buttonStart.Enabled        = true;
            buttonHalt.Enabled         = false;
            listViewSourcePDFs.Enabled = true;
        }
        private void StartProcess()
        {
            string sourceFolder = currentSourceFolder;
            string targetFolder = currentTargetFolder;

            buttonStart.Enabled        = false;
            buttonHalt.Enabled         = true;
            labelStatus.Text           = "Starting processing at " + sourceFolder + ".";
            listViewSourcePDFs.Enabled = false;

            int cntTotal = listViewSourcePDFs.CheckedItems.Count;

            progressBarConvert.Maximum = cntTotal * progTickMult;  // first mark means started
            progressBarConvert.Minimum = 0;
            progressBarConvert.Step    = 1;
            progressBarConvert.Visible = true;
            progressBarConvert.Value   = 1; // show some progress

            List <string> SourcesList = new List <string>();

            foreach (ListViewItem thisItem in listViewSourcePDFs.CheckedItems)
            {
                String pdfName = sourceFolder + "/" + thisItem.SubItems[0].Text;
                SourcesList.Add(pdfName);
                thisItem.SubItems[1].Text = "Queued";
            }
            thisBackWrkARgs thisArg = new thisBackWrkARgs();

            thisArg.SourceList    = SourcesList;
            thisArg.targetFolder  = targetFolder;
            thisArg.cutSuffixText = cutSuffixText;
            thisArg.outPutExtType = outPutExtType;
            if (!backgroundWorker1.IsBusy)
            {
                backgroundWorker1.RunWorkerAsync(thisArg);
            }
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            thisBackWrkARgs thisArg = e.Argument as thisBackWrkARgs;
            int             inDx    = 0;

            foreach (string fullPDFpathname in thisArg.SourceList)
            {
                if (File.Exists(fullPDFpathname))
                {
                    backgroundWorker1.ReportProgress(inDx, Path.GetFileName(fullPDFpathname));
                    PDFtoWhateverC.ConvertPDF.ConvertPDFToMultipleImagesAKS(fullPDFpathname, thisArg.targetFolder, thisArg.cutSuffixText, thisArg.outPutExtType);
                    inDx++;
                }
                else    // source file became missing on the way!
                {
                    // negative progress signals a missing file but inDxZeroMissing used for indx found missing
                    if (inDx == 0)
                    {
                        backgroundWorker1.ReportProgress(inDxZeroMissing, Path.GetFileName(fullPDFpathname));
                    }
                    else
                    {
                        backgroundWorker1.ReportProgress(-inDx, Path.GetFileName(fullPDFpathname));
                    }
                    inDx++;
                }

                //if cancellation is pending, cancel work.
                if (backgroundWorker1.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
        }