473,408 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Close Window Command or Monitor Print Queue?

I'm attempting to build an ASP.NET (VB) application that will do
server-side printing of PDF files. I have used a Process object to
launch Adobe's AcroRd32 program with the /t switch which causes it to
open an Acrobat Reader window and silently send the document I want
printed to a local network printer:

Dim psiInfo As ProcessStartInfo = New ProcessStartInfo
(pathtoadobe, "/t " + filename + " " + printername)

psiInfo.CreateNoWindow = True
psiInfo.UseShellExecute = True

Dim procPrint As Process = New Process()
procPrint.StartInfo = psiInfo
procPrint.Start()

This works nicely except for the fact that after it finishes printing,
the Acrobat window stays open on the server. I had thought the /t
switch would cause it to close when it was finished, but I was
apparently wrong. This is unacceptable, because after ten print runs
on the server, I'll end up with ten open acrobat windows!

How can I deal with this problem? It's a simple matter to kill the
process, but how do I know when it's done sending the job to the
printer? If I kill it too early, I could lose pages or corrupt the job
or worse. Is there any way to send something like a WM_COMMAND to the
Adobe window (if I can manage to get a handle to it)? Is there any way
for my to look at the printer's print queue within my ASP.NET code (if
I can do that, I can just check to see if the queue is empty, at which
point I'd know I can kill the process)?

Jun 22 '06 #1
1 4183
Just in case someone else has a similar issue someday, I thought I'd
post the solution I ended up finding.

It's easier to monitor the print queue. Basically you import two Win32
API calls (see pinvoke.net's winspool section for help on that). The
two you need are OpenPrinter and EnumJobs. Once that's done, it's a
simple matter to check the printer to see how many jobs are running on
it, and kill the Adobe process at the appropriate time.
br*****@gmail.com wrote:
I'm attempting to build an ASP.NET (VB) application that will do
server-side printing of PDF files. I have used a Process object to
launch Adobe's AcroRd32 program with the /t switch which causes it to
open an Acrobat Reader window and silently send the document I want
printed to a local network printer:

Dim psiInfo As ProcessStartInfo = New ProcessStartInfo
(pathtoadobe, "/t " + filename + " " + printername)

psiInfo.CreateNoWindow = True
psiInfo.UseShellExecute = True

Dim procPrint As Process = New Process()
procPrint.StartInfo = psiInfo
procPrint.Start()

This works nicely except for the fact that after it finishes printing,
the Acrobat window stays open on the server. I had thought the /t
switch would cause it to close when it was finished, but I was
apparently wrong. This is unacceptable, because after ten print runs
on the server, I'll end up with ten open acrobat windows!

How can I deal with this problem? It's a simple matter to kill the
process, but how do I know when it's done sending the job to the
printer? If I kill it too early, I could lose pages or corrupt the job
or worse. Is there any way to send something like a WM_COMMAND to the
Adobe window (if I can manage to get a handle to it)? Is there any way
for my to look at the printer's print queue within my ASP.NET code (if
I can do that, I can just check to see if the queue is empty, at which
point I'd know I can kill the process)?


Jun 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: vooose | last post by:
Suppose execution of a particular thread T1 hits Monitor.Enter(obj); //critical section and blocks at the first line. (ie someone else is in the critical section) Now suppose more threads...
4
by: Charles Law | last post by:
I've been using monitors a bit lately (some of you may have heard ;-) ) and then up pop Manual and AutoResetEvents , and they look for all the world like the same thing. Are they...
22
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the...
2
by: www.brook | last post by:
I have a VC++.net code. Two threads are created, one thread keeps appending elements to the queue, another keeps deleting an element from the queue. I tried to use monitor, but it seems that the...
13
by: Jonathan Amsterdam | last post by:
I think there's a slight design flaw in the Queue class that makes it hard to avoid nested monitor deadlock. The problem is that the mutex used by the Queue is not easy to change. You can then...
0
by: Russell Thomas | last post by:
I wanted to see if anyone knew of anything in the .net framework 2.0 that I could tap into for monitoring a printer’s print queue. I found some articles about tying into the API but I was hoping...
12
by: Perecli Manole | last post by:
I am having some strange thread synchronization problems that require me to better understand the intricacies of Monitor.Wait/Pulse. I have 3 threads. Thread 1 does a Monitor.Wait in a SyncLock...
1
by: Thomas Strauss, SRS | last post by:
Hi, I have a really hard time to find the access rights required for monitoring a printing queue or share in windows XP or Win2000/2003 server. We have an application that will remote control...
2
by: DeveloperX | last post by:
Hi, Below is a hacked up version of an example I found on MSDN. My only change was to add a third thread and some Sleeps. That's where my question(s) comes in. In the original it seems to work...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.