Add a cancellation token to stop long running document generation
Author: FrancGithubCreated Dec 15, 2025Updated Dec 15, 2025
I would propose to add in the while a check if a cancellation token, passed as an argument, has a cancel request instead of while (true)
So, if I need abort a long running document generation, I can cancel the token passed to GeneratePdf
var ctsGenPdf = new CancellationTokenSource();
var doc = Document.Create(.....);
doc.GeneratePdf(pp.PdfOutputPath, ctsGenPdf.Token);Source: QuestPDF/QuestPDF