簡體   English   中英

多線程運行GhostScript.net時出現錯誤

[英]Multiple Thread Run GhostScript.net With Error

我運行兩個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}",
        };
  }

您必須以特定方式構建Ghostscript DLL,以使其具有線程安全性,而這不是標准DLL的構建方式。

如果您嘗試將非線程安全的DLL與兩個線程一起使用,則它實際上將拒絕啟動第二個實例,adnd將返回gs_error_Fatal(-100)。

您可以執行此操作,但是需要重建DLL,需要定義編譯器標志GS_THREADSAFE。 被告知; 如果這樣做,某些設備將停止工作,則它們本質上不是線程安全的。 這些是Artifex不擁有版權的“貢獻”設備,因此無法修改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM