首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多线程运行GhostScript.net时出错

多线程运行GhostScript.net时出错
EN

Stack Overflow用户
提问于 2019-07-15 22:46:19
回答 1查看 149关注 0票数 0

我运行两个线程,每个线程处理它的pdf,每个线程都有它自己的GhostscriptProcessor,如果我只启动一个线程是没有问题的,但是如果我启动两个线程,gohstScript.net会给出错误"error occured call to 'gsapi_new_instance‘is made:-100“,我尝试了版本gs64bit和版本gs32bit,结果是一样的

我的代码作为伙伴,有没有人能帮我?非常感谢。

代码语言:javascript
复制
 Thread t1 = new Thread(processPdf);
 Thread t2 = new Thread(processPdf);

 t1.Start("D:\\T1.PDF");

 t2.Start("D:\\T2.PDF");


  public static void processPdf(object obj) {

        GhostscriptVersionInfo gvi = null;
        GhostscriptProcessor   ghostscript = null;
        try
        {

  gvi = 
  GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | 
  GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
            ghostscript = new GhostscriptProcessor(gvi);

            string outputPath = obj.ToString();
            string input = null;

            if (outputPath.Contains("T1")) {
                input = @"D:\TestFiles\111.pdf";
            }
            else {
                input = @"D:\TestFiles\222.pdf";
            }
            string[] args = GetArgs(input, outputPath);              

            ghostscript.Process(args);

        }
        catch (Exception ex) {

            Console.WriteLine(ex.StackTrace+"|"+ex.Message);

        }

    }//多线程

 private static string[] GetArg(string inputFile, string outputFile)
  {
         return new[] {
         $"gs",
         $"-o",
         $"{outputFile}",
         $"-dNoOutputFonts",   
         $"-sDEVICE=pdfwrite",
         $"{inputFile}",
        };
  }
EN

回答 1

Stack Overflow用户

发布于 2019-07-15 23:52:18

您必须以特定的方式构建Ghostscript DLL,以使其成为线程安全的,这不是标准DLL的构建方式。

如果您尝试使用具有两个线程的非线程安全动态链接库,它确实会拒绝启动第二个实例,并返回gs_error_Fatal (-100)。

你可以这样做,但是你需要重新构建动态链接库,你需要定义编译器标志GS_THREADSAFE。请注意,如果您这样做,一些设备将停止工作,它们本质上不是线程安全的。这些都是“贡献”的设备,Artifex没有版权,因此无法修改。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57042221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档