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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > General Discussion
  New Posts New Posts RSS Feed - Multi-Threading from C#
  FAQ FAQ  Forum Search   Register Register  Login Login

Multi-Threading from C#

 Post Reply Post Reply
Author
Message
davidgm View Drop Down
Beginner
Beginner


Joined: 20 Jul 17
Location: Spain
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidgm Quote  Post ReplyReply Direct Link To This Post Topic: Multi-Threading from C#
    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.
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 31 Jul 17 at 9:14AM
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.
Back to Top
davidgm View Drop Down
Beginner
Beginner


Joined: 20 Jul 17
Location: Spain
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidgm Quote  Post ReplyReply Direct Link To This Post Posted: 01 Aug 17 at 11:50AM
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.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store