Ghostscript.NET多线程问题 [英] Ghostscript.NET Multithreading Issue

查看:253
本文介绍了Ghostscript.NET多线程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们运行的每月流程中最长的部分是自动切片并将某些PDF转换为图像.读取每个PDF并将其转换为3个不同的PDF,然后将这3个PDF转换为图像以将其放置在发送给客户的电子邮件中.这些PDF每个客户都是唯一的,我们每月向至少15,000个(通常更像是22k)客户发送PDF.

The longest part of a monthly process we run is the automated slicing and conversion of some PDFs to images. Each PDF is read in, converted to 3 different PDFs, and those 3 are converted to images to be placed in e-mails to customers. The PDFs are unique per-customer, and we send a monthly PDF to at least 15,000 (frequently more like 22k) customers.

我们的PDF生成和切片已经是多线程的,但是我一直在研究如何并行化其余部分.

Our PDF generation and slicing is already multithreaded, but I've been looking into parallelizing the remaining bits of it.

为此,我将我们的过程转换为使用Ghostscript.NET,它声称是一个支持并行化Ghostscript的库.

To that end, I have converted our process to use Ghostscript.NET, which purports to be a library that supports parallelizing Ghostscript.

为此,我将此代码包装在Parallel.Foreach()循环中,该循环中的每个迭代都在不同的初始PDF上工作:

To that end, I wrapped this code in a Parallel.Foreach() loop, where each iteration through the loop works on a different initial PDF:

      GhostscriptVersionInfo gsVersionInfo = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);

      GhostscriptProcessor processor = null; 

        try
        {
            //sArgs is an array of arguments for ghostscript
            processor = new GhostscriptProcessor(gsVersionInfo, true);
            processor.StartProcessing(sArgs, new ConsoleStdIO(true,false,true));
            while (processor.IsRunning)
            {
                Thread.Sleep(100);
            }
        }

当我运行上面的代码并强制Parallel.Foreach仅使用1个线程(禁用并行化)时,它的运行方式与以前一样并正确生成了所有文件.如果我使用5度并行化,它将开始引发错误.这些错误千差万别,但往往表示输入的PDF文件格式错误,使我认为ghostscript处理器实际上不是线程安全的,并且会相互依赖对方的输入.

When I run the above code and force the Parallel.Foreach to use only 1 thread (disabling parallelization) it runs just like it used to and generates all the files correctly. If I use 5 degrees of parallelization, it begins throwing errors. These errors vary, but tend to indicate malformed input PDF files, making me think that the ghostscript processors aren't actually threadsafe, and are stepping on each other's inputs.

如何正确使用Ghostscript.NET在不同文件上同时运行ghostscript的多个实例?

How do I correctly use Ghostscript.NET to run multiple instances of ghostscript, on different files, simultaneously?

推荐答案

我正在使用具有多线程功能的Ghostscript.NET. 您上面共享的代码应位于Parallel.For循环内.是的,整个代码意味着从

I am using Ghostscript.NET with multi-threading. The code you shared above should be inside the Parallel.For loop. yes the entire code which means starting from

GhostscriptVersionInfo gsVersionInfo = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);

直到最后,它都应该起作用.正如上面提到的@KenS,每个多线程进程应使用不同的GhostscriptProcessor实例.

till the end and it should work. As @KenS mentioned above, each multi-threaded process should use a different instance of GhostscriptProcessor.

这篇关于Ghostscript.NET多线程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆