empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 589 forks source link

Opening PDFs from multiple threads #149

Closed adamizbekia closed 1 year ago

adamizbekia commented 2 years ago

Expected Behavior

PDFSharp works in a concurrent environment.

Actual Behavior

We have a solution that opens PDF files from different threads and reads their content. Sometimes multiple threads get stuck and we think this might be a concurrency issue. Was this library designed to work in a concurrent environment?

This is the corresponding call stack:

PdfSharp.dll!PdfSharp.Pdf.Advanced.PdfCrossReferenceTable.TransitiveClosureImplementation(System.Collections.Generic.Diction ary<PdfSharp.Pdf.PdfItem, object> objects, PdfSharp.Pdf.PdfObject pdfObject) Line 348 PdfSharp.dll!PdfSharp.Pdf.Advanced.PdfCrossReferenceTable.TransitiveClosure(PdfSharp.Pdf.PdfObject pdfObject, int depth) Line 257 PdfSharp.dll!PdfSharp.Pdf.Advanced.PdfCrossReferenceTable.Compact() Line 160 PdfSharp.dll!PdfSharp.Pdf.IO.PdfReader.Open(System.IO.Stream stream, string password, PdfSharp.Pdf.IO.PdfDocumentOpenMode openmode, PdfSharp.Pdf.IO.PdfPasswordProvider passwordProvider) Line 322 PdfSharp.dll!PdfSharp.Pdf.IO.PdfReader.Open(string path, string password, PdfSharp.Pdf.IO.PdfDocumentOpenMode openmode, PdfSharp.Pdf.IO.PdfPasswordProvider provider) Line 131

ThomasHoevel commented 1 year ago

Each PdfDocument should only be accessed by a single thread at any time, but multiple threads should be able to work with different documents at the same time. With Preview 1 of version 6.0.0 we fixed concurrency issues while creating PDFs.