我需要打印一个pdf文件与ProcessStartInfo。
string docInvoicePath = @"[Path]";
string printername = "\"PRN-OFFICE\"";
string driver = "\"Xerox Global Print Driver PS\"";
string port = "\"[IP]\"";
ProcessStartInfo psInfo = new ProcessStartInfo
{
FileName = @"""C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32""",
Arguments = String.Format("/s /o /h /t " + docInvoicePath + " " + printername + " " + driver + " " + port),
Verb = "print",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = false
};
Process process = Process.Start(psInfo);
process.WaitForExit(6000);
if (process.HasExited == false)
{
process.Kill();
}
process.Close();filename和arguments是正确的,它们在cmd中粘贴时工作。代码正常工作,但是在Process.Start之后,当涉及到WaitForExit时,程序还没有完成。我得到了超时错误:
System.Threading.ThreadAbortException:线程被中止。在System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle,UInt32 millisecondsTimeout,Boolean,Boolean ) at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle,Int64 millisecondsTimeout,Boolean,Boolean ) at System.Diagnostics.Process.WaitForExit(Int32毫秒)。
我搜索并尝试了一些东西,比如设置<httpRuntime executionTimeout="300"/>,并遇到一个500,或者类似于使用process.WaitForExit(6000);和更高级别的代码,在这些代码中,没有什么东西被打印出来。
有什么错误吗?还是我漏掉了什么?
编辑:我更改了上面的代码块。现在,代码在调试模式下工作,但在发布时仍然不会打印我的文档。我还尝试使用不同的用户。在调试模式下,代码打印文档,但在杀死查询中运行。
ProcessStartInfo.Verbs返回一个参数异常,但我不知道为什么。
发布于 2017-09-19 06:55:22
经过大量的尝试、测试和搜索,我确信我的代码可以工作。所以我仍然不知道为什么我的代码停止工作。但是,从服务器上的Adobe 9.0改为7.0,它现在可以工作了。
当我在本地使用Adobe 9.0进行调试时,它也起作用了,所以我想可能是在was服务器上进行了更新。我还没确认呢。
https://stackoverflow.com/questions/46237997
复制相似问题