我需要用ProcessStartInfo
打印pdf文件。ProcessStartInfo WaitForExit超時
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: Thread was being aborted. at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Diagnostics.Process.WaitForExit(Int32 milliseconds)...
我搜索並嘗試了一些東西,如設置<httpRuntime executionTimeout="300"/>
並在代碼process.WaitForExit(6000);
和更高療法那裏得到了印沒有exeption但沒有碰上或類似。
有沒有錯誤或我錯過了什麼?
編輯: 我改變了我的代碼塊上面。現在代碼在調試模式下工作,但它仍然不會在發佈時打印我的文檔。我也嘗試使用不同的用戶。 在調試模式下,代碼打印文檔,但運行在kill查詢。
ProcessStartInfo.Verbs
返回一個參數異常但我不知道爲什麼。
你是否阻止主線程? – Fildor
我不這麼認爲,我該如何檢查? – MaxW
我只是想知道爲什麼它應該被中止,如果在ASP.NET中,我不知道如果阻塞主線程這麼久會發生什麼。在普通的.net/WinForms應用程序中,您的GUI將無響應。但在ASP上 - 我真的不知道是否有機制中止長時間運行的東西。出於某種原因你是否必須等待退出?如果不是隻是省略它。如果是,請嘗試在工作線程上執行所有這些操作,並查看是否也有中止。 – Fildor