S
Shashi
Hi,
The following program attempts to print a pdf file and then delete it.
I am using Process.start with the command
(AcroRd32.exe /t "pdf-file-name" "printer-name") to do it.
The file gets printed. But, the process does not terminate. I have
called the WaitForExit() method after Process.Start and it blocks the
execution infinitely. If I remove the WaitForExit method, I cannot
delete the file because I get an error message saying the file is in
use by another process ("AcroRd32.exe").
One option is to use WaitForExit(20000) and wait for 20 seconds before
killing the process using the Kill() method but that would result in
each print job taking atleast 20 seconds.
Here is what I have.
Any ideas/suggestions? Thanks in Advance.
' This is just the relevant part of the code
Dim printedFileName As String
Dim printedFileInfo As FileInfo
printedFileName = "c:\myfile.pdf"
printedFileInfo = New FileInfo(printedFileName)
' Print the first file in the queue
startProcess("AcroRd32.exe", " /t " + printedFileName + "
\\IAN-P4\HP3330", dirName)
Console.Writeline("Printed file :" + printedFileName)
Try
' Delete the file
printedFileInfo.Delete()
' File successfully deleted
Console.WriteLine("Deleted file :" + printedFileName)
Catch ex As Exception
Console.WriteLine("Could not delete the file " +
printedFileName + vbCrLf + ex.Message + vbCrLf + ex.StackTrace)
End Try
Public Function startProcess(ByVal strCommand As String, _
ByVal strArguments As String, _
ByVal strWd As String)
Dim psi As New ProcessStartInfo
' Initialize the ProcessStartInfo structure
psi.FileName = strCommand
psi.Arguments = strArguments
psi.WorkingDirectory = strWd
psi.RedirectStandardInput = False
psi.RedirectStandardOutput = False
psi.UseShellExecute = False
Dim proc As New Process
' Start the process
proc = proc.Start(psi)
proc.WaitForExit()
End Function
The following program attempts to print a pdf file and then delete it.
I am using Process.start with the command
(AcroRd32.exe /t "pdf-file-name" "printer-name") to do it.
The file gets printed. But, the process does not terminate. I have
called the WaitForExit() method after Process.Start and it blocks the
execution infinitely. If I remove the WaitForExit method, I cannot
delete the file because I get an error message saying the file is in
use by another process ("AcroRd32.exe").
One option is to use WaitForExit(20000) and wait for 20 seconds before
killing the process using the Kill() method but that would result in
each print job taking atleast 20 seconds.
Here is what I have.
Any ideas/suggestions? Thanks in Advance.
' This is just the relevant part of the code
Dim printedFileName As String
Dim printedFileInfo As FileInfo
printedFileName = "c:\myfile.pdf"
printedFileInfo = New FileInfo(printedFileName)
' Print the first file in the queue
startProcess("AcroRd32.exe", " /t " + printedFileName + "
\\IAN-P4\HP3330", dirName)
Console.Writeline("Printed file :" + printedFileName)
Try
' Delete the file
printedFileInfo.Delete()
' File successfully deleted
Console.WriteLine("Deleted file :" + printedFileName)
Catch ex As Exception
Console.WriteLine("Could not delete the file " +
printedFileName + vbCrLf + ex.Message + vbCrLf + ex.StackTrace)
End Try
Public Function startProcess(ByVal strCommand As String, _
ByVal strArguments As String, _
ByVal strWd As String)
Dim psi As New ProcessStartInfo
' Initialize the ProcessStartInfo structure
psi.FileName = strCommand
psi.Arguments = strArguments
psi.WorkingDirectory = strWd
psi.RedirectStandardInput = False
psi.RedirectStandardOutput = False
psi.UseShellExecute = False
Dim proc As New Process
' Start the process
proc = proc.Start(psi)
proc.WaitForExit()
End Function