Print then immediately delete file contents

jimbaloo

Member
Joined
Jun 20, 2007
Messages
7
Programming Experience
Beginner
I have an application in which I am printing large numbers of letters. The app builds each letter from a template, copies the contents to a print doc, and when the print doc has 250 letters it will print and then the contents of the doc will be deleted so the next batch of letters can be built.
The problem is that unless I sleep the thread the contents are deleted before the entire print job has time to spool and I am losing some of the letters.
VB.NET:
                If (index Mod 250) = 0 Then
                    CommonWordHelper.PrintDocument(printDoc)
                    'sleep the thread to allow the print job to spool
                    System.Threading.Thread.Sleep(index * 10)
                    'delete everything in the print document
                    printDoc.Content.Delete()
                    initial = True
                End If
As you can see from the code I am giving each letter 10 milliseconds to spool. Does anyone know of a way to wait until the print job is completely spooled before continuing that won't mean waiting for a random (relatively) amount of time?
Thanks
Jim
 
Back
Top