PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 3:05 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Jun 06, 2023 5:00 am 
Offline

Joined: Tue Jun 06, 2023 4:44 am
Posts: 4
I attempted to utilize C# multithreading to process a PDF document, where each thread handles a separate page and then combines them. Overall, it functions well, but occasional errors occur. Specifically, the error stems from the XGraphics.DrawImage method, indicating that the same key already exists in the table.

To address this issue, I implemented a lock on the document object before calling the XGraphics.DrawImage method. While this solution resolves the problem and prevents conflicts, it does introduce some slowdown because the method has to wait for other threads to finish their tasks due to the document lock.

I'm uncertain about whether XGraphics.DrawImage directly relates to the document (potentially involving ID retrieval) and requires locking the entire document to prevent the error. If it is possible, Could I consider separating the locking mechanism from the DrawImage method. This way, I could lock the document specifically for operations related to keys or IDs, while allowing DrawImage to proceed independently on its own thread. This separation might potentially enhance performance by minimizing the need for thread synchronization caused by the document lock. Consequently, it could result in improved efficiency.

Thank you.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 06, 2023 8:10 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
SuperMENG wrote:
I attempted to utilize C# multithreading to process a PDF document, where each thread handles a separate page and then combines them.
PDFsharp was designed to support document creation with only a single thread per document, but multiple threads creating individual documents at the same time.

With your approach of using multiple threads for a single document, you may encounter problems.
Adding an image to a PDF requires adding several objects to the PDF. Several pages can share the same image.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 07, 2023 7:28 am 
Offline

Joined: Tue Jun 06, 2023 4:44 am
Posts: 4
Thomas Hoevel wrote:
SuperMENG wrote:
I attempted to utilize C# multithreading to process a PDF document, where each thread handles a separate page and then combines them.
PDFsharp was designed to support document creation with only a single thread per document, but multiple threads creating individual documents at the same time.

With your approach of using multiple threads for a single document, you may encounter problems.
Adding an image to a PDF requires adding several objects to the PDF. Several pages can share the same image.


Thank you for the information. I have now resolved this issue by simultaneously composing several documents using multithreading. As a result, the processing speed has been maximized to the best extent possible


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 117 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group