How to Properly Interrupt Convert or Save Actions in Aspose.Pdf.Document

Hello,

I need help interrupting the Convert or Save actions of an Aspose.Pdf.Document. I tried adapting a sample code I found, but without success.

The goal is to stop these operations and free hardware resources if the process takes longer than a specified timeout. In the example below, I attempt to interrupt the action after 15 seconds, but it seems that the process continues running even after calling Interrupt.

What is the correct way to achieve this goal?

Here is the code I am using:

using Aspose.Pdf;
using Aspose.Pdf.Multithreading;

string dataDir = @"c:\temp4";
InterruptMonitor monitor = new InterruptMonitor();
PdfWorker worker = new PdfWorker(dataDir + “cfc.pdf”, dataDir + “cfc-out.pdf”, monitor);

Thread thread = new Thread(new ThreadStart(worker.ThreadProc));

try
{
thread.Start();

Thread.Sleep(15000);
monitor.Interrupt();

thread.Join();

}
finally
{

}

class PdfWorker
{
private readonly string inputPath;
private readonly string outputPath;
private readonly InterruptMonitor monitor;

public PdfWorker(string inputPath, string outputPath, InterruptMonitor monitor)
{
    this.inputPath = inputPath;
    this.outputPath = outputPath;
    this.monitor = monitor;
}

public void ThreadProc()
{
    using (Document document = new Document(this.inputPath))
    {
        InterruptMonitor.ThreadLocalInstance = this.monitor;

        try
        {
            PdfFormatConversionOptions options = new PdfFormatConversionOptions(PdfFormat.PDF_A_1B);
            document.Convert(options);
            document.Save(this.outputPath);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
        finally
        {
            InterruptMonitor.ThreadLocalInstance = null;
        }
    }
}

}

@rpassos

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-59519

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.