I have a very simple application that is printing TIFF files to a variety of networked printers. The printers are all installed on 3 different print servers, while the application runs on a separate machine. (Lets call them Print1,2,3, and App1.)
Most of the time this works well, but lately I have noticed that certain new printers (HP P4515x model using PCL6 drivers) are causing a spike in the number of handles opened by spoolsv.exe on App1. One document can raise the handles by 500, and they are never released, which eventually leads to the App1 machine having to be rebooted if this isn't caught in time. None of the actual print servers seem affected by this issue.
The code is doing something very similar in concept to this, but from a background service running under a domain account: MSDN Link. I am specifying the printer using the \print3\deptP4515x naming convention.
[Not sure if this goes on StackOverflow or ServerFault, but I think due to the possible driver issue, it should be on here?]
EDIT: I ran procexp and see that of the 1243 handle it has grown to, 1135 are this: Key HKLM\SOFTWARE\Hewlett-Packard\San Diego Shared IO
Try reproducing the symptom with another driver, like the HP LaserJet 4 or 4100 PCL. Use the built-in driver, not a custom driver that is supplied by the vendor.
If the symptom occurs with those drivers, it is probably not an issue with the P4515 driver.
Run a find on your %systemroot%\system32\spool\drivers folder, searching for hpbmini.dll and hpcdmc32.dll. Older versions of these files are known to cause major issues in printing.
Your are Dispose()-ing of your PrintDocument objects are you? This is a frequent omission from MS .NET examples.
Check the application code. Make sure printer connections are created inside of
using
statements. Otherwise managed code is not guaranteed to close them in a timely matter, and how fast things are release really could depend on the nature of the printer driver (meaning the different model printers could be a symptom of this deeper problem).