InterruptMonitor

Hello,

The release notes for v23.11 contains:

PDFNET-47791	Support for thread interruption

and the class Aspose.Pdf.Multithreading.InterruptMonitor has been added.

Is there documentation / advice on how to use this new feature?

Thanks

@ast3

Please check the below code example for this feature:

public void InterruptExample()
{
    string outputFile = testdata + "47791_output.pdf";
    //this is some large text, used Lorem Ipsum in 8350 characters to cause suspension 
    string text = ExampleApp.LongText;
    using (InterruptMonitor monitor = new InterruptMonitor())
    {
        RowSpanWorker worker = new RowSpanWorker (outputFile, monitor);
        Thread thread = new Thread(new ThreadStart(worker.Work));
        thread.Start();

        // The timeout should be less than the time required for full document save (without interruption).
        Thread.Sleep(500);

        // Interrupt the process
        monitor.Interrupt();

        // Wait for interruption...
        thread.Join();
    }
    private class RowSpanWorker
    {
        private readonly string outputPath;
        private readonly InterruptMonitor monitor;

        public RowSpanWorker(string outputPath, InterruptMonitor monitor)
        {
            this.outputPath = outputPath;
            this.monitor = monitor;
        }
        public void Work()
        {
            string text = InterruptMonitorTests.LongText;
            using (var doc = new Document())
            {
                InterruptMonitor.ThreadLocalInstance = this.monitor;
                var page = doc.Pages.Add();

                var table = new Aspose.Pdf.Table
                {
                    DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F)
                };

                var row0 = table.Rows.Add();

                // add a cell that spans for two rows and contains a long-long text
                var cell00 = row0.Cells.Add(text);
                cell00.RowSpan = 2;
                cell00.IsWordWrapped = true;
                row0.Cells.Add("Ipsum Ipsum Ipsum Ipsum Ipsum Ipsum ");
                row0.Cells.Add("Dolor Dolor Dolor Dolor Dolor Dolor ");

                var row1 = table.Rows.Add();
                row1.Cells.Add("IpsumDolor Dolor Dolor Dolor Dolor ");
                row1.Cells.Add("DolorDolor Dolor Dolor Dolor Dolor ");

                page.Paragraphs.Add(table);

                try
                {
                    doc.Save(this.outputPath);
                }
                catch (Exception ex)
                {
                    Assert.IsTrue(ex is OperationCanceledException);
                }
            }
        }
    }
}