We are using Aspose.PDF for .NET 24.4 version. While we generating PDF report, the windows service running our .NET code using Aspose to generate PDF gets stuck in below function.
Aspose.Pdf.Document.ProcessParagraphs();
Restarting the service solves the problem and we have eliminated all load or infrastructure related possible root causes.
Could you please help guide us here.
@saravanamani
Could you please share more details about how exactly you generate PDF file with example of code and input PDF if it’s present so we could investigate this issue?
hello
i’m saravanamani coworker
We trying to create pdf document.
We do multiple calls method Paragraphs.Add(paragraph); (lot of)
And at end call ProcessParagraphs(); for doc
Unfurnatelly time to time call of ProcessParagraphs never ends.
We can’t stable reproduce this, and never on our development PC (windows 10/11). But on server time to time got these problems. Restart service as usual resolve this problem.
@pavlo.korenivskyi
Could you share the code that causes such behaviour - maybe there’s something that will give us a hint why such unending cycle could occur?
I can’t share code or its parts (
We create doc, add page, then add a lot of paragraphs.
On OnBeforePageGenerate We set header and footer.
them, before saving document, we call ProcessParagraphs().
@pavlo.korenivskyi
In that case it seems that possibly either some of paragraphs causes such behavior or just amount of paragraphs may be the case
I’ll try to investiagate and recreate such situation but currently it’s too little information for creating a task for development team
Hello Ilya,
Do you want the code we use to generate the doc?
Is the a limit on paragraphs or number of lines or character per call/ doc?
Also restarting the service resolves the issue? Is there any type of local cache or something within this function we need to consider?
@saravanamani
Yes, the code would be helpful for investigation
If there’s limit on paragraphs per call then I haven’t heard about it
There could be some limitations if you’re running demo version but as I understand from the fact that the issue is unstable and sometimes it succedes it’s not the case here
I think that yes, maybe there could be some ways to free cache but I will need to do some investigation before I can say certainly
we have a valid license for Aspose Total at Enterprise level. is there any way we can get someone on a call, so we can walk through the code or show the issue?
@ilya.zhuykov
Could You please give me more info about this class? Class InterruptMonitor | Aspose.PDF for .NET API Reference
Do I can use this to break ProcessParagraps? And how?
@pavlo.korenivskyi
As I know for now InterruptMonitor is used mostly for Save() interruption
I have the following example for such usage
using (InterruptMonitor monitor = new InterruptMonitor())
{
SaveDocumentWorker worker = new SaveDocumentWorker(null, outputDir + "47791.pdf"), monitor);
Thread thread = new Thread(new ThreadStart(worker.ThreadProc));
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 SaveDocumentWorker
{
private readonly string inputPath;
private readonly string outputPath;
private readonly InterruptMonitor monitor;
public SaveDocumentWorker(string inputPath, string outputPath, InterruptMonitor monitor)
{
this.inputPath = inputPath;
this.outputPath = outputPath;
this.monitor = monitor;
}
public void ThreadProc()
{
using (var document = new Document())
{
InterruptMonitor.ThreadLocalInstance = this.monitor;
//user code
document.Save(this.outputPath);
}
}
}
I’m not sure it will work on ProcessParagraphs operation at the moment - I’ll check and if it doesn’t I’ll add task for such function
@saravanamani
I’ll ask if there’s possibility to do something like that
I try. But instead thread I will use task (for “pure threads” I need more time).
@saravanamani
No, we can’t arrange such call - such conversation format is not supported
@pavlo.korenivskyi
There’s public function Document.FreeMemory()
maybe it can help with optimizing resourses