Example #1
0
        private bool DoExportToPdf(FlexCelPdfExport PdfExport)
        {
            PdfThread MyPdfThread     = new PdfThread(PdfExport, PdfSaveFileDialog.FileName, cbAllSheets.Checked);
            Thread    PdfExportThread = new Thread(new ThreadStart(MyPdfThread.ExportToPdf));

            PdfExportThread.Start();
            using (PdfProgressDialog Pg = new PdfProgressDialog())
            {
                Pg.ShowProgress(PdfExportThread, PdfExport);
                if (Pg.DialogResult != DialogResult.OK)
                {
                    PdfExport.Cancel();
                    PdfExportThread.Join(); //We could just leave the thread running until it dies, but there are 2 reasons for waiting until it finishes:
                                            //1) We could dispose it before it ends. This is workaroundable.
                                            //2) We might change its workbook object before it ends (by loading other file). This will surely bring issues.
                    return(false);
                }

                if (MyPdfThread != null && MyPdfThread.MainException != null)
                {
                    throw MyPdfThread.MainException;
                }
            }
            return(true);
        }