The process seems to be caught and never returns when converting files that contain EMF files. The EMF files were created by a software no longer being used. Current EMF files work fine.
Thanks for your inquiry. 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. Sample inherited class code is as follows:
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,
() =>
{
token.BindToCurrentThread();
Save(fileName);
}, timeout);
return finished;
}
private bool SaveWithTimeout(InterruptionToken token, ThreadStart threadStart, int timeout)
{
Thread workerThread = new Thread(threadStart);
workerThread.Start();
bool finished = workerThread.Join(timeout);
if (!finished)
{
token.Interrupt();
}
return finished;
}
}
}
Sample usage is as follows:
MyDocument myDoc = new MyDocument(@"C:\BigDoc.docx");
bool done = myDoc.TryToSave(@"C:\BigDoc.pdf", 60000);
Console.WriteLine(done ? "Converted" : "Interrupted by timeout.");
Tahir.manzoor,
Thanks for your quick response. I was able to get the conversion process to quit with the InterruptionToken. When I try and remove the failed file there is a process that is preventing me from removing the unfinished converted file. is their a cancel or close feature?
Thanks for your inquiry. We have already logged a feature request as WORDSNET-11575 in our issue tracking system to stop Document.Save method after specific time. You will be notified via this forum thread once this feature is available. The shared code example is workaround of this issue. We apologize for your inconvenience.
Could you please share the steps and code that you are using to remove the failed file? We will then provide you more information about it.
The issues you have found earlier (filed as WORDSNET-11575) have been fixed in this Aspose.Words for .NET 22.1 update also available on NuGet.