Printing from Service's thread

Posted on 2004-11-03
Medium Priority
Last Modified: 2010-04-05
Hi Experts,

I have a Service Application written in Delphi 6. I need to print a page to the default printer, but this has to be done in a thread.
Procedure doprint;
 Printer.Canvas.TextOut(x,y, 'My text to print');
This seems to be ok, but sometimes, printing stops. Exactly, the document is put into the print spooler's queue, but never printed out. If I delete the documents from the print queue it works again.

I think the problem is due the fact, the Canvas object is not thread-safe, so I've put it into synchronize like this:
The problem still exists. Delphi's help tells that, the method called with synchronize will be executed in the main VCL thread.
But I have not VCL thread, I have a service which is also a thread...
Moreover, I have no error message or exception at all...

Question by:spbltd
LVL 17

Accepted Solution

Wim ten Brink earned 250 total points
ID: 12495401
This could be a security related issue. Personally, I've never tried to print from a service anyway, because then I would need to provide a user account for this service and make sure that account has access to at least a default printer. I'm not even sure if a service actually has any real access rights to the printer in the first place.

About synchronizations, this is required if you're working with a GUI-based application that depends on the Forms unit. When you call the Synchronize method of a thread, it will actually send a Windows message to the main thread. But a service doesn't have a message handler thus this would just fail. You would have to use a critical section to make sure printer access is synchronized.

Author Comment

ID: 12509440
Finally we have found the problem, it was a hardware failure.

But your comments about the synchronization is still useful, so I accept your answer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question