2 Gig Print Spooler process

S

Scott M

I'm printing a directory of about 500 multi-page tifs to a high speed
printer and the spooler process is killing me!!!

here is a little code.....



Public Function PrintImage(ByVal SourceFile As String) As Boolean

Try
ImageToPrint = FromFile(SourceFile)

PageNumber = 0
ImagePages = ImageToPrint.GetFrameCount(FrameDimension.Page())
Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
End Try

Try

PDocument.DocumentName = SourceFile
PDocument.Print()

Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
Return False
End Try

Return True

End Function

Then the event on the global variable PDocument is being raised for the
pages....

Private Sub PagePrintFunction(ByVal sender As Object, ByVal e As
PrintPageEventArgs) Handles PDocument.PrintPage
Try
ImageToPrint.SelectActiveFrame(FrameDimension.Page, PageNumber)

PageNumber = PageNumber + 1

e.Graphics.DrawImage(ImageToPrint, 0, 0,
(e.PageSettings.PaperSize.Width - 40), (e.PageSettings.PaperSize.Height -
50))

If PageNumber < ImagePages Then
e.HasMorePages = True
End If
Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
End Try
End Sub

This is not only really slow with larger images but as stated in the title,
my print spooler process turns into a 2 Gig memory monster after only about
160 images!!!!!!!!! Does anyone have a better solution or can tweak the
code? I'm kinda at my wits end over this. I've tried creating and
disposing of the PDocument variable in my loop that prints each file and
still the process grows.

MANY Thanks
Scott
 
S

ShaneO

Scott said:
I'm printing a directory of about 500 multi-page tifs to a high speed
printer and the spooler process is killing me!!!

here is a little code.....



Public Function PrintImage(ByVal SourceFile As String) As Boolean

Try
ImageToPrint = FromFile(SourceFile)

PageNumber = 0
ImagePages = ImageToPrint.GetFrameCount(FrameDimension.Page())
Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
End Try

Try

PDocument.DocumentName = SourceFile
PDocument.Print()

Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
Return False
End Try

Return True

End Function

Then the event on the global variable PDocument is being raised for the
pages....

Private Sub PagePrintFunction(ByVal sender As Object, ByVal e As
PrintPageEventArgs) Handles PDocument.PrintPage
Try
ImageToPrint.SelectActiveFrame(FrameDimension.Page, PageNumber)

PageNumber = PageNumber + 1

e.Graphics.DrawImage(ImageToPrint, 0, 0,
(e.PageSettings.PaperSize.Width - 40), (e.PageSettings.PaperSize.Height
- 50))

If PageNumber < ImagePages Then
e.HasMorePages = True
End If
Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
End Try
End Sub

This is not only really slow with larger images but as stated in the
title, my print spooler process turns into a 2 Gig memory monster after
only about 160 images!!!!!!!!! Does anyone have a better solution or
can tweak the code? I'm kinda at my wits end over this. I've tried
creating and disposing of the PDocument variable in my loop that prints
each file and still the process grows.

MANY Thanks
Scott
Just a quick thought.... I believe your problem is because the spooler
isn't purged until the last page is printed. Have you tried dividing
the overall print task into smaller numbers of pages, and then calling
the print function several times? You'd have to handle the Start-Page
for each call in this case, but it might work.... Then again, you might
just end up with several smaller spooler tasks that add-up to be 2 gig,
but I would at least expect each spooler process to be deleted once all
the pages in each process had been printed.

Anyone else tried this?

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
J

Jeffrey Tan[MSFT]

Hi Scott,

Thanks for your post!

Does your tif file have 500 frames or do you have 500 files in a directory
for printing?

ShaneO's reply seems make sense, you may give it try and feedback the
result here.

Regarding this issue, I recommend you try to use some existing softwares
that can read these tif files for printing, can this problem be reproduced?
I suspect it may be a bug of spooler process since your code snippet is
really simple.

Anyway, I will wait for your feedback. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Scott M

The Printimage function gets called 500 times for tiffs that have about 10 -
30 pages in each. I haven't installed the service on any other machines to
see if it will konk out the server there, either.

I really stinks to have to restart the spooler and to restart the machine
after only printing 100 tiffs.

And as far as other software, Jeff. What do you suggest? This is a server
side process for a production orientated environment so I can't have much
downtime.

Thanks
Scott
 
A

Andrew Morton

Scott said:
The Printimage function gets called 500 times for tiffs that have
about 10 - 30 pages in each. I haven't installed the service on any
other machines to see if it will konk out the server there, either.

I really stinks to have to restart the spooler and to restart the
machine after only printing 100 tiffs.

And as far as other software, Jeff. What do you suggest? This is a
server side process for a production orientated environment so I
can't have much downtime.

Could you monitor the size of the spooler directory and wait for it to go
down a bit before adding more print jobs to it?

Andrew
 
J

Jeffrey Tan[MSFT]

Hi Scott,

Based on my experience, any type of image viewer software will have print
function build-in. You may choose one supports tif file, and try to print
the tif files one by one. I am not sure if mspaint.exe supports tif image,
can you give it a try?

Looking at the issue's nature, it is hard for us to give it a reproduce on
my side. It would require intensive troubleshooting which would be done
quickly and effectively with direct assistance from a Microsoft Support
Professional through Microsoft Product Support Services. They may perform
some remote debugging to your machine to identify the root cause.

You can contact Microsoft Product Support directly to discuss additional
support options you may have available, by contacting us at 1-(800)936-5800
or by choosing one of the options listed at
http://www.microsoft.com/services/microsoftservices/srv_support.mspx

Finally, if you want to troubleshoot the spooler process memory issue, it
is helpful to use UMDH.EXE from windbg to. The tool can be used to obtain
call stack information of various memory block allocation of a process.
Please refer to below for more information:
"Umdhtools.exe: How to Use Umdh.exe to Find Memory Leaks"
http://support.microsoft.com/kb/268343/

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Andrew Morton

Scott said:
"Andrew Morton" wrote

Scott said:
It doesn't go down...

What, not even after the images have been printed? I'm suggesting that
rather than try to sent umpteen gigabytes all in one go, you give the
printer (and print spooler) a chance to catch up/breathe. And avoid filling
up the disk the spool folder resides on.
...even after the service that spools the images is
restarted.

The print spooler service should not delete the files in the spool folder
just because it's been restarted.

The spool folder location is in the registry at
HKLM\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Print\Printers\DefaultSpoolDirectory
(and other locations; I can't remember which one to set to change it).

Andrew
 
M

Michael D. Ober

This actually sounds like a bug in the Printimage function. Does this
function close each print job properly. By this I mean are the spool files
closed once they have been created. I have seen image processing programs
not properly close the images when they are done with them.

Mike Ober.


Scott M said:
The Printimage function gets called 500 times for tiffs that have about
10 - 30 pages in each. I haven't installed the service on any other
machines to see if it will konk out the server there, either.

I really stinks to have to restart the spooler and to restart the machine
after only printing 100 tiffs.

And as far as other software, Jeff. What do you suggest? This is a
server side process for a production orientated environment so I can't
have much downtime.

Thanks
Scott


"Jeffrey Tan[MSFT]" said:
Hi Scott,

Thanks for your post!

Does your tif file have 500 frames or do you have 500 files in a
directory
for printing?

ShaneO's reply seems make sense, you may give it try and feedback the
result here.

Regarding this issue, I recommend you try to use some existing softwares
that can read these tif files for printing, can this problem be
reproduced?
I suspect it may be a bug of spooler process since your code snippet is
really simple.

Anyway, I will wait for your feedback. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
S

Scott M

I'm not too sure what you mean. I've changed the code considerably since
I've last posted it (trying to figure out what is happening). Installed new
print drivers and messed with settings on the printer with our own hardware
support (Direct printing instead of spooling the print jobs)

It's just a huge enigma to me. Even after the application hasn't been
printing for over two hours now the spoolersv.exe process stands at
1,140,324 K in task manager. the users printed about 700 single page tiff
files today. Here is the code that printed the images.

Private Sub PagePrintFunction(ByVal sender As Object, ByVal e As
PrintPageEventArgs)
Static Dim PageNumber As Integer = 0

Try
ImageToPrint.SelectActiveFrame(FrameDimension.Page, PageNumber)

PageNumber += 1

e.Graphics.DrawImage(ImageToPrint, New RectangleF(0, 0,
(e.PageSettings.PaperSize.Width - 40), (e.PageSettings.PaperSize.Height -
50)))

If PageNumber < ImagePages Then
e.HasMorePages = True
Else
e.HasMorePages = False
e.Graphics.Dispose()
PageNumber = 0
End If

Catch ex As Exception
General.WriteToEventLog("PagePrintFunction" & vbCrLf &
ex.ToString, "Print Class", EventLogEntryType.Error)
Throw ex
End Try
End Sub

Public Function PrintImage(ByVal SourceFile As String) As Boolean

Try
ImageToPrint = FromFile(SourceFile)

ImagePages = ImageToPrint.GetFrameCount(FrameDimension.Page())
Catch ex As Exception
General.WriteToEventLog("Getting Image Frames: " & vbCrLf &
ex.ToString, "Print Class", EventLogEntryType.Error)
End Try

Try
Using PDocument As New PrintDocument

PDocument.PrinterSettings.PrinterName = PrinterName
PDocument.DocumentName = SourceFile

AddHandler PDocument.PrintPage, AddressOf PagePrintFunction

PDocument.Print()
End Using

Catch ex As Exception
General.WriteToEventLog("Print Document: " & vbCrLf &
ex.ToString, "Print Class", EventLogEntryType.Error)
Return False
End Try

Return True

End Function

Public Sub PrintFolderContents()

Dim ExtensionFilter As String = "*." & Filter
Dim FileNameList As String() = Directory.GetFiles(Folder,
ExtensionFilter)

Try
General.WriteToEventLog("Starting to print " & Folder, "Print
Class", EventLogEntryType.Information)

FileNameList = Directory.GetFiles(Folder, ExtensionFilter)

Array.Sort(FileNameList)

If _ToggleArchiveBit Then
turnOffSwapFileBits(FileNameList)
End If
Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
End Try

Try

For i As Integer = 0 To FileNameList.Length - 1
If PrintImage(FileNameList(i)) Then
If _ToggleArchiveBit Then
turnOnAttributeBit(FileNameList(i))
End If
Else
General.WriteToEventLog("File " & FileNameList(i) & "
did not properly Print.", "Print Class", EventLogEntryType.Warning)
End If

Next

Catch ex As Exception
General.WriteToEventLog(ex.ToString, "Print Class",
EventLogEntryType.Error)
Finally
If Not ImageToPrint Is Nothing Then
ImageToPrint.Dispose()
End If
End Try

End Sub

The speed at which the jobs are pushed into the printer is less then optimal
as well.


Michael D. Ober said:
This actually sounds like a bug in the Printimage function. Does this
function close each print job properly. By this I mean are the spool
files closed once they have been created. I have seen image processing
programs not properly close the images when they are done with them.

Mike Ober.


Scott M said:
The Printimage function gets called 500 times for tiffs that have about
10 - 30 pages in each. I haven't installed the service on any other
machines to see if it will konk out the server there, either.

I really stinks to have to restart the spooler and to restart the machine
after only printing 100 tiffs.

And as far as other software, Jeff. What do you suggest? This is a
server side process for a production orientated environment so I can't
have much downtime.

Thanks
Scott


"Jeffrey Tan[MSFT]" said:
Hi Scott,

Thanks for your post!

Does your tif file have 500 frames or do you have 500 files in a
directory
for printing?

ShaneO's reply seems make sense, you may give it try and feedback the
result here.

Regarding this issue, I recommend you try to use some existing softwares
that can read these tif files for printing, can this problem be
reproduced?
I suspect it may be a bug of spooler process since your code snippet is
really simple.

Anyway, I will wait for your feedback. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top