我运行两个线程,每个线程处理它的pdf,每个线程都有它自己的GhostscriptProcessor,如果我只启动一个线程是没有问题的,但是如果我启动两个线程,gohstScript.net会给出错误"error occured call to 'gsapi_new_instance‘is made:-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}",
};
}发布于 2019-07-15 23:52:18
您必须以特定的方式构建Ghostscript DLL,以使其成为线程安全的,这不是标准DLL的构建方式。
如果您尝试使用具有两个线程的非线程安全动态链接库,它确实会拒绝启动第二个实例,并返回gs_error_Fatal (-100)。
你可以这样做,但是你需要重新构建动态链接库,你需要定义编译器标志GS_THREADSAFE。请注意,如果您这样做,一些设备将停止工作,它们本质上不是线程安全的。这些都是“贡献”的设备,Artifex没有版权,因此无法修改。
https://stackoverflow.com/questions/57042221
复制相似问题