0

我运行两个therad,每个线程处理它的pdf,每个线程线程都有它自己的GhostscriptProcessor,如果我只启动一个线程没有问题,但是如果我启动两个线程,gohstScript.net会给出错误“调用时发生错误” 'gsapi_new_instance' 是:-100" 我尝试版本 gs64bit 和版本 gs32bit ,结果是一样的

我作为研究员的代码有人可以帮助我吗?多谢。

 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}",
        };
  }
4

1 回答 1

1

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

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

你可以这样做,但是你需要重建DLL,你需要定义编译器标志GS_THREADSAFE。被告知; 如果您这样做,某些设备将停止工作,它们本质上不是线程安全的。这些是 Artifex 不拥有版权的“贡献”设备,因此无法修改。

于 2019-07-15T15:52:17.983 回答