We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add API to Interrupt Word to PDF conversion when it takes time using .NET

@tahir.manzoor Some of the other aspose products have had timeout code (https://docs.aspose.com/email/net/aspose-email-for-net-20-7-release-notes/) added to prevent this zombie state. I see hanging issues on multiple threads in your forums of lots of your products so surely adding the same timeout code will help.
We’ve got hanging aspose code when saving Word to PDF for which I’ll create a new thread but it would be such a better customer experience if this timeout code could be added throughout the product on all the save methods, which is where the majority of hanging problems seems to occur.


You can use InterruptionToken class instance and bind it to the current thread executing Aspose.Words code. Then calling Interrupt on the token instance should break the execution.

Please use the following code example to achieve your requirement.

using System.Threading;
using Aspose.Words;
namespace conversion
    /// <summary>
    /// My Aspose document.
    /// </summary>
    public class MyDocument : Aspose.Words.Document
        public MyDocument(string fileName) : base(fileName) {}
        public bool TryToSave(string fileName, int timeout)
            InterruptionToken token = new InterruptionToken();
            bool finished = SaveWithTimeout(token,
                () =>
                }, timeout);
            return finished;
        private bool SaveWithTimeout(InterruptionToken token, ThreadStart threadStart, int timeout)
            Thread workerThread = new Thread(threadStart);
            bool finished = workerThread.Join(timeout);
            if (!finished)
            return finished;

Sample usage is as follows:

MyDocument myDoc = new MyDocument(@"C:\in.docx");
bool done = myDoc.TryToSave(@"C:\output.pdf", 60000);
Console.WriteLine(done ? "Converted" : "Interrupted by timeout.");

OK thanks @tahir.manzoor; we’ll give this a try


Further to my previous post, the InterruptionToken class is now obsolete.In your case, we suggest you please implement IPageLayoutCallbac interface to have your own custom method called during build and rendering of page layout model.

We have added this feature in Aspose.Words 20.5. Please check the release notes from here:
Aspose.Words for .NET 20.5 Release Notes