DevTrain Startseite Visual Studio 1 Magazin  
  
  
SUCHEN:  
ARTIKEL ONLINE: 525   

Kategorien
.NET
Datenbanken
Web
XML

Allgemein
Camp
Foren
Events
Persönliche Einstellungen
Registrieren
Prämien Shop
Kontakt
Impressum
Über DevTrain

Autoren



 

Forum: VB.NET | Thema: specific problem: monitoring processes | Von: Markus Pöhler ( 03.12.2004 16:24)

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


Betreff Von Datum
Re: specific problem: monitoring processes
Hi Markus,<br><br>there are two solutions i can offer you:<br><br>1. Make your own Threading Model. (not easy)<br>2. Use MessageQueuing (Its like Bacth Processing)<br><br>hope that helps<br><br>Tobi
Tobi Ulm 03.12.2004 17:41
Re: specific problem: monitoring processes
Hi.<br><br>What I do now is also not easy and it does not work, so I would prefer sth. else not easy and running. How can I build a threading model?<br>I've never heard about that 2nd thing. Could you...
G. Guest 04.12.2004 17:35

Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!

 Betreff:
 Nachricht: Den Beitrag finden Sie nun unter: http://beta.devtrain.de/foren Die Benutzerdaten und Foreninhalte von beta.devtrain.de und www.devtrain.de sind die selben.
Sie können sich dort sogar per RSS über neue Inhalte informieren lassen.
Bei Problemen bitte direkt Mail an asp [AT] ppedv.de.

 Signatur:

  



Login
Username:


Passwort:






Passwort vergessen?

Visual Studio 1 Magazin

© Copyright 2003 ppedv AG