Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Multi-Threading from C# |
Post Reply |
Author | |
davidgm
Beginner Joined: 20 Jul 17 Location: Spain Status: Offline Points: 8 |
Post Options
Thanks(0)
Posted: 28 Jul 17 at 5:32PM |
Hello,
I am facing several issues using threads in C# with this library. I know that the library is not multi-thread safe, but i also did read this: "However, Debenu Quick PDF Library can be used in a multi-threaded environment so long as a separate instance of the library is created by each thread." I create different threads in my C#, and i init the library this way in every thread: public Foxit(string KEY) { // Different filename for 32-bit and 64-bit DLL string DLLprefix = "DebenuPDFLibraryDLL"; string DLL64prefix = "DebenuPDFLibrary64DLL"; string dllName; // Check to see if IntPtr size is 4. // If 4 then it's 32-bit, if 8 then // it is 64-bit. if (IntPtr.Size == 4) { dllName = DLLprefix + VERSION.ToString("D4") + ".DLL"; // 32 bits } else { dllName = DLL64prefix + VERSION.ToString("D4") + ".DLL"; // 64 bits } // Load the library DPL = new PDFLibrary(dllName); // Unlock the library m_started = DPL.UnlockKey(KEY) == 1; } However, when several threads are using the library, i get the following exception: Excepcion: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. in DebenuPDFLibraryDLL1312.PDFLibrary.PrintDocument(String PrinterName, Int32 StartPage, Int32 EndPage, Int32 Options) The method causing the exception is PrintDocument, and this is what i'm using from the lib. I solved the problem temporarily by creating a little executable that does the printing part only. I do a shell exec from each thread to this executable. It is not optimal, but it is working properly, and i get the multi-core boost that i need for my application. Speed is crucial for my project. Am i missing any special initialization for a muti-threaded C# application ? Thank you very much. |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
Surely it is more likely that the printing operation is the part that does not support multi-threading? It could be an issue with the printer driver. Are both threads attempting to write to the same physical printer? Is spooling enabled and working for the printer port? Google tells me that 0x80004005 can arise when sharing a printer, but it is hard to find a definitive meaning for this code.
A simpler solution than using a separate program might be to enclose the call to PrintDocument inside a critical section, especially if printing to the same printer is likely.
|
|
davidgm
Beginner Joined: 20 Jul 17 Location: Spain Status: Offline Points: 8 |
Post Options
Thanks(0)
|
Thanks for the reply.
I tested 4 different threads, each one printing to a different printer, and each printer from a diferent manufacturer with a different driver. It failed. I tested with spooling enabled & disabled, and with the spooler set to print immediately and set to print after last page has been spooled. Everything failed. Print processor was set to winprint & raw in all the cases. If you use a lock() with a critical section before the PrintDocument, it works ofc, but you lose all the multi-core boost this way. So far, the best solution for multi-core printing is a little helper (print.exe) that runs in a separate process. This way it works, even sending many jobs to the same printer at the same time. I have been testing many different libraries from different companies, and this library is the best by far in terms of printing speed. |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store