I am a beginner so please be patient. I am trying to solve problems with existing code. We have a tree view where user may check off multiple files (tif,pdf, doc etc) for printing. When the print buttton is clicked each document should be printed. Each document must be printed in full before the next one starts. The docs are not printing in full or in order. I have attached the code for review.
Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
If tn.Tag = "FILE" And tn.Checked Then
wComplete = False
If (tn.FullPath.Length > 0) Then
Try
Dim WordProcess As Process = New Process
WordProcess.StartInfo.FileName = tn.FullPath
WordProcess.StartInfo.Verb = "Print"
WordProcess.StartInfo.CreateNoWindow = True
WordProcess.StartInfo.UseShellExecute = True
WordProcess.EnableRaisingEvents = True
AddHandler WordProcess.Exited, AddressOf Me.ProcessExited
WordProcess.Start()
If wComplete = True Then
tn.Checked = False
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "TIM")
End Try
Else
End If
End If
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes)
End If
Next
End Sub
Friend Sub ProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
Dim WordProcess As Process = DirectCast(sender, Process)
WordProcess.Close()
wComplete = True
End Sub
I have tried several things to make this work including adding WaitToExit after the Start. It appears to me that the "print" process whether Adobe (pdf) or Microsoft Imaging (tif) is not really exiting. Can anyone help?
Thanks
Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
If tn.Tag = "FILE" And tn.Checked Then
wComplete = False
If (tn.FullPath.Length > 0) Then
Try
Dim WordProcess As Process = New Process
WordProcess.StartInfo.FileName = tn.FullPath
WordProcess.StartInfo.Verb = "Print"
WordProcess.StartInfo.CreateNoWindow = True
WordProcess.StartInfo.UseShellExecute = True
WordProcess.EnableRaisingEvents = True
AddHandler WordProcess.Exited, AddressOf Me.ProcessExited
WordProcess.Start()
If wComplete = True Then
tn.Checked = False
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "TIM")
End Try
Else
End If
End If
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes)
End If
Next
End Sub
Friend Sub ProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
Dim WordProcess As Process = DirectCast(sender, Process)
WordProcess.Close()
wComplete = True
End Sub
I have tried several things to make this work including adding WaitToExit after the Start. It appears to me that the "print" process whether Adobe (pdf) or Microsoft Imaging (tif) is not really exiting. Can anyone help?
Thanks