Some weeks ago, a customer contacted us about some intermittent issues he had when printing barcodes in a Windows Service using our Barcode Professional SDK for .NET
Barcode Pro SDK for .NET is written using 100% managed code based on the “standard” drawing engine provided by .NET Framework which is basically a wrapper around GDI+, that’s System.Drawing classes.
The printing functionality using the “standard” drawing engine is mainly under System.Drawing.Printing namespace and the key class behind it is PrintDocument which we used in some guides demoing barcode printing using our Barcode Pro SDK for .NET
Although this approach seems to be working fine in Windows Forms applications, it seems that in Windows Service it has some limitation or “not supported” tag as is stated in this page which basically says:
Classes within the System.Drawing.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.
Sadly, there’s no solution to that if try to use our Barcode Pro SDK for .NET (or Barcode Pro for Windows Forms) in Windows Service scenarios. However, one possible alternate approach to bypass this issue is to replace the “drawing” engine. Another drawing engine in .NET Framework is the one based on WPF (Windows Presentation Foundation) which was introduced in .NET 3.0
WPF drawing engine is NOT based on GDI+ but on DirectX and the printing classes is available under System.Printing
It seems that WPF printing can be safely used in Windows Service projects. Taken advantage of this, we wrote a guide for printing barcodes in Windows Service using our Barcode Professional for WPF (which is 100% based on WPF drawing engine and NOT on GDI+) In that guide we tried to reproduce two common scenarios i.e. printing a single page document as well as a multipage document with barcodes.
We hope that guide helps you as a starting point for more complex printing scenarios.