Chris said:
You are not sending it to a windows printer queue? Usually windows takes
care of this for you.
If you are doing something funny you should think about using one thread
to do the job and having a queue that holds the jobs. All the worker
threads just can add to the queue, the printer thread then processes the
queue.
The whole class is a bit much to cut-n-paste, but basically, it is built
around this declaration:
Private Shared WithEvents pd as PrintDocument
The public function that invokes the class is
Public Function SendFileToPrinter(ByVal ThisFile As String, ByVal ThisPrinter
As String) _
As Boolean
which creates a new instance of pd (if necessary) and sets up margins,
Landscape orientation, and tells pd what printer to use. Then, it opens the
text file using a shared instance of StreamReader and calls pd.Print(). The
..NET library takes over and, at the start of each new page of text, calls
pd_PrintPage by raising the PrintPage event on pd.
pd_PrintPage is a private shared sub handling the PrintPage event of the pd
object. It looks to the instance of StreamReader to fetch the next line of the
text document, then calls Graphics.DrawString to draw the text to the printer.
The routine then reads the next line, looping until either a maximum number of
lines has been read, a form feed character is encountered or the end of file
is reached. When all of the pages have been printed (indicated by setting
HasMorePages = False in the event parameter, ev As PrintPageEventArgs), the
call to pd.Print() returns. SendFileToPrinter then ties up any loose ends and
returns with true if there were no errors or false if there were.
Yes, all I need is to dump a text file to a network printer, but that seems to
be impossible under .NET 2.0 :-/
Anyway, this class worked great until I went to a threaded version of a
service I've written. I need to figure out how to make PrinterClass
thread-safe and allow only one thread to use it at a time. I don't think
allowing multiple instances of the class would work, as you will still have
competing processes trying to control the one physical printer. As now
written, all of the class internals are shared, both the declares and the two
methods.