You are viewing limited content. For full access, please sign in.

Question

Question

Document Export

SDK
asked on March 18, 2015

Hi,

 

I have a console app that search a set of data from LF and Export them. I'm using the following code snnipet:

 

public void ExportDocuments(IEnumerable<LaserficheEntry> documents)
        {
            DocumentExporter documentExporter = new DocumentExporter();
            documentExporter.IncludeAnnotations = true;
            documentExporter.BlackoutRedactions = true;
            documentExporter.PageFormat = DocumentPageFormat.Jpeg;
            documentExporter.CompressionQuality = 90;
 
            Parallel.ForEach(documents, document =>
                {
                    DocumentInfo documentInfo = Document.GetDocumentInfo(document.ToString(), laserficheSession);
 
                    try
                    {
                        if (documentInfo.AllPages.GetTotalPageCount() > 0)
                        {
                            documentExporter.ExportPdf(documentInfo, documentInfo.AllPages, PdfExportOptions.IncludeText, documentSignerSettings.ExportedFilesFolder + documentInfo.Name + ".pdf");
 
                            Console.WriteLine("Documento exportado: " + document.Name);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Error importing file " + document.Name);
                    }
                });
            
        }

 

This code makes use from Parallel.Foreach that starts threads behind the scenes and export the files. At some point of the code execution I'm getting an error "The current request could not be performed because there are too many existing operations running.[9035]. Besides reducing my calls do sdk api, what would be the best approach?

 

Thanks,

Best Regards, Caio Himmelsbach

1 0

Replies

replied on March 18, 2015 Show version history

There is an overload of Parallel.ForEach which takes a ParallelOptions instance that allows you to control the behavior. Set the MaxDegreeOfParallelism property to limit how much parallelism is used to execute the body of the loop. I recommend setting a value of 3 or 4.

If you need more parallelism, then create a task which creates a new Session and then repeatedly pulls documents from a ConcurrentQueue and exports them. You will want to launch several tasks in parallel. You can launch further tasks from inside each task to increase the parallelism which takes the Session and just does the export operation.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.