mpoehler

mpoehler

  • NA
  • 1
  • 0

Process monitoring does not realy work.

Dec 3 2004 10:26 AM
Hi out there, my specific job is to realize some printing from my Application. It will run on terminal servers, so I am sure about the installed local software there. (Acrobat, Office) It must do the following: - allow user to select from pool of documents liested (almost PDF & Excel) - when pressing print button print all these documents on default printer or (if user selects on different one) - allow the user to continue working with the application while printer is still printing the docs My solution so far: When firing print button I change the default printer of the user if he selected another printer. (this works perfect) Then I start new processes with "print" verb for every document and load them into the associated executable programm (e.g. Acrobat). So the docs should be printed to default printer. This also works so far. BUT: After testing a while I foud some timing problems. If I fire about 7 PDF documents to load, print and close again, the number of really sent docs to printer is random. Somtimes 7 are printed, somtimes just one, somtimes three...I can watch the opened Acrobat Reader opening not all of the documents instances it should do. Every started process gets a Handler listening for Exited event. So I can make output and see when a document is exited. Although the message of exit comes up, the docs are not in printer queue. It seems the loading and closing is too fast. Sometimes I get messages about opening a document, but the event handler never comes up to close this doc again. I defined just one doc to be opened on button press ==> If I pause before repressing the button, the doc is always printed. But If I do not pause, there is a delta of #pressed and #printed. It chokes on sth.! Is there a problem with the Eventhandler EXITED?? Should I use something else?? Here my code parts: Dim istarted, iclosed as integer Sub startfile(ByVal ffile As String) Dim pr As Process = New Process istarted += 1 pr.EnableRaisingEvents = True pr.StartInfo.FileName = ffile pr.StartInfo.UseShellExecute = True pr.StartInfo.Verb = "Print" AddHandler pr.Exited, AddressOf ProcessExited pr.Start() debug("File: " & ffile & " ID: " & pr.Id.ToString & " (" & pr.StartTime.ToString & ") startet. No." & iStarted) End Sub Friend Sub ProcessExited(ByVal sender As Object, ByVal e As System.EventArgs) Dim myProcess As Process = DirectCast(sender, Process) iClosed += 1 debug("The process " & myProcess.StartInfo.FileName & " exited : " & myProcess.ExitTime & ". Exit Code: " & myProcess.ExitCode & " ID:" & myProcess.Id.ToString & "(No." & iClosed & ")") myProcess.Close() If iStarted = iClosed Then debug("all Files printed: " & iClosed & "/" & iStarted) End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click iStarted = 0 iClosed = 0 startfile("C:\1420.html.pdf") startfile("C:\1426.html.pdf") startfile("C:\1459.html.pdf") startfile("C:\1427.html.pdf") End Sub Thanks, MP