Hi,
I have tried to call this code in parallel because otherwise it is very slow to render all pages:
Code:
using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append))
{
documentRenderer.RenderPage(gfx, pageIndex);
}
Sometimes it is working, so theoretically this is not a big problem.
But sometimes it fails with the following error:
Quote:
System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
at PdfSharp.Pdf.Advanced.PdfFontTable.GetFont(XFont font)
at PdfSharp.Pdf.PdfPage.GetFontName(XFont font, PdfFont& pdfFont)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.GetFontName(XFont font, PdfFont& pdfFont)
at PdfSharp.Drawing.Pdf.PdfGraphicsState.RealizeFont(XFont font, XBrush brush, Int32 renderingMode)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.Realize(XFont font, XBrush brush, Int32 renderingMode)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.DrawString(String s, XFont font, XBrush brush, XRect rect, XStringFormat format)
at PdfSharp.Drawing.XGraphics.DrawString(String text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
at PdfSharp.Drawing.XGraphics.DrawString(String s, XFont font, XBrush brush, Double x, Double y)
at MigraDoc.Rendering.ParagraphRenderer.RenderWord(String word)
at MigraDoc.Rendering.ParagraphRenderer.RenderText(Text text)
at MigraDoc.Rendering.ParagraphRenderer.RenderElement(DocumentObject docObj)
at MigraDoc.Rendering.ParagraphRenderer.RenderLine(LineInfo lineInfo)
at MigraDoc.Rendering.ParagraphRenderer.Render()
at MigraDoc.Rendering.DocumentRenderer.RenderHeader(XGraphics graphics, Int32 page)
at MigraDoc.Rendering.DocumentRenderer.RenderPage(XGraphics gfx, Int32 page, PageRenderOptions options)
at MigraDoc.Rendering.DocumentRenderer.RenderPage(XGraphics gfx, Int32 page)
Is it possible to make this specific Dictionary thread safe?
Or can I add all fonts before starting the rendering?
Thanks
Thomas