empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
492 stars 114 forks source link

Async IO should be supported #177

Open cfauchere opened 1 day ago

cfauchere commented 1 day ago

Reporting an Issue Here

Expected Behavior

PDFSharp supports async API

Actual Behavior

PDFSharp does not support async API

Example

PdfReader.Open vs PdfReader.OpenAsync PdfDocument.Save vs PdfDocument.SaveAsync

Why is it important?

Look at implementation of PdfDocument OpenFromStream it calls stream.Read(array, 0, 1024); which is blocking. Blocking on IO can lead to threadpool starvation.

ThomasHoevel commented 1 day ago

There is PdfDocument.SaveAsync.

You can read the PDF file into a MemoryStream and use that with PdfReader.Open.