Resolving PDFDraw.Export issue in a multi-threaded process

Q: I'm having an issue using the Export function in PDFDraw in a
process that is multithreaded. I've attached a sample program that
seems to recreate the issue. The symptom is an "Unknown Exception"
thrown by the Export call. It seems to work fine with 10 or so
threads, but at 30 it throws an exception quickly.

Any suggestions on what may be causing the exception?

MultithreadedQueueManager manager = new MultithreadedQueueManager(30,
for (int i = 0; i < NUM_EXPORTS; i++) {

private List<byte[]> ConvertPDFByteArrayToTiff(byte[] baPDF) {
    using (PDFDoc pdfdoc = new PDFDoc(baPDF, baPDF.Length)) {

        bool greyScale = true;

        using (PDFDraw pdfdraw = new PDFDraw(300)) {
            List<byte[]> pages = new List<byte[]>();
            ObjSet hint_set = new ObjSet();
            Obj gray_hint = hint_set.CreateDict();
            gray_hint.PutNumber("BPC", 1);

            for (PageIterator itr = pdfdoc.GetPageIterator();
itr.HasNext(); itr.Next())
                using (TemporaryFileSystemFile file = new
                    if (greyScale)
                        pdfdraw.Export(itr.Current(), file.FileName,
"TIFF", gray_hint);
                        pdfdraw.Export(itr.Current(), file.FileName,

            return pages;

A: The problem is that your 32-bit process is running out of memory.
In your sample code you are creating 30 threads, each of which is
rendering a PDF at 300 DPI. Just to store the main image/buffer you
would need at least 33MB which does not account for any auxiliary
memory requirements used to store input and output files etc. Since 32-
bit process is limited to 2GB you are hitting out of memory condition.

There are several solutions:

a) Use 64-bit version of PDFNet
b) Decrease the number of active threads in your render queue
c) Decrease the DPI at which you are rasterizing PDF.