on long running test (> 1000 documents) Aspose.Words.Document.Save(Stream stream, SaveFormat saveFormat) method throws subj error. This error doesn’t seem to be caused by a particular document as it processes them fine during shorter test. Aspose Words for Net v 14.10 Windows 8.1 Enterprise x64, running on single thread inside console app in 64 bit mode.
you’re correct, the documents are saved in the loop, as you can see each on its own thread even though in my case MAX_THREAD_COUNT was 1 so although each conversion happens on its own thread the total # of threads remains 1. The highlighted line throws the error::
foreach (FileData f in files)
{
int th_cnt;
lock (this._pdfList)
{
th_cnt = this._thCount;
}
while (th_cnt > MAX_THREAD_COUNT)
{
Thread.Sleep(20);
lock (this._pdfList)
{
th_cnt = this._thCount;
}
}
Thread th = new Thread(() => this.Convert(f, docConverterFactory, out_dir));
th.Start();
Thread.Sleep(20);
}
the actual conversion code returning content inside byte array:
using(MemoryStream ms = new MemoryStream())
{
this.SaveToPdf(ms);
ms.Position = 0L;
return ms.ToArray();
}
public override void SaveToPdf(Stream outputStream)
{
Document doc = this.GetDocument();
doc.Save(outputStream, SaveFormat.Pdf);
}
private Document GetDocument()
{
LoadOptions lo = new LoadOptions();
lo.LoadFormat = ConvertSupportedLoadFormat(this._contentType);
using (MemoryStream ms = new MemoryStream(this.InputContent))
{
Document result = new Document(ms, lo);
result.UpdateFields();
return result;
}
}
internally code uses its own Document instance created by docConverterFactory object, nothing is shared between these threads. The only thing they share is the output document folder but by that time document is already written internally into byte array, each into its own.
What would you suggest to fix the problem?
- Your input Word documents.
- Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.
It seems latest version 16.3 doesn’t have this problem anymore. I’m still running the test over large set of documents and so far I haven’t seen single error over 20,000 + docs.