Showing posts with label Printing. Show all posts
Showing posts with label Printing. Show all posts

Thursday, December 8, 2011

FlowDocument issues

We created this service that would fire prints on a network printer. When tested for performance, the code showed signs of memory leaks. This was strange, because I was expecting the .Net's garbage collector to cleanup unused objects. Perhaps there were some objects that were left to be disposed.

So, as part of our analysis, using WinDebugger, a memory dump of the process was collected. Using DebugDiag, this dump was analyzed. Multiple objects of type FlowDoument (used in CreateXpsDoc) were found blocking the finalizer queue. Googling for this type led us to some similar problems with this type being discussed in tech forums. It seems FlowDocument uses System.Windows.Threading.Dispatcher to free all resources

Reference: http://stackoverflow.com/questions/952985/flowdocument-memory-issue-in-c-sharp

Solution:
Execute these lines of code between printing and deleting the xps file.
var dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
dispatcher.BeginInvokeShutdown(System.Windows.Threading.DispatcherPriority.SystemIdle);
System.Windows.Threading.Dispatcher.Run();

Monday, November 21, 2011

PDF Printer for Windows

Whenever I need to have a copy of something important, such as a travel ticket, I like to print to file instead of a regular printer. This way, I could always print it again without having to generate the material again. I used to use the Microsoft Office Document Image Writer for this. This is one of the non-default features that comes with Microsoft Office 2003 or 2007, but has been discontinued in Office 2010.
http://support.microsoft.com/kb/982760

So, when I have Office 2010 on my new PC, I install just this component from the Office 2007 installer, up until now. The MDI or TIF format works fine locally, but if I have to share it with someone else, it doesnt work as well.

For instance, when I booked a ticket for my father, I feel sending a PDF is a much better option. So, I googled for it, and the first paid ad brought this free PDF printer for Windows.
http://www.pdflite.com/printer?gclid=CPDAgNqyyawCFUwaQgodmHatrQ

Tried and tested, works fine.