I need to print a pdf-file with 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();
The filename
and arguments
are correct they work when pasted in cmd
.
The code works properly but after Process.Start
when it comes to WaitForExit
the programm doesn`t finish. I get the timeout error:
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)...
I searched and try a few things like setting <httpRuntime executionTimeout="300"/>
and run into a 500 or like in the code with process.WaitForExit(6000);
and higher ther where no exeption but nothing got printed.
Is there an error or am i missing something?
EDIT: I changed my codeblock above. Now the code works in debug mode but it still won´t print my document when published. I also tried to use a different User. In debug mode the code prints the document but runs in the kill query.
The ProcessStartInfo.Verbs
returns a Argument Exception but i don´t know why.