Forcing Printer Handle Thread Safety


When working with printer handles in an application obtained from functions such as OpenPrinter and CreateDC,
it is the caller’s responsibility to only access the object from one thread at a time.  This should always be followed
when developing new code. 

If you’re stuck with some code that doesn’t respect this and accesses the object on multiple threads concurrently as
a race condition, there is something that you can try that may help the issue.  There is a registry key that will cause
the spooler subsystem to forcibly restrict access to the object to one thread at a time.  This will have a performance
penalty, so it’s definitely not desirable unless absolutely needed.  In order to make this behavior change, set
the registry key as indicated below and restart the spooler service:

 

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print]
"SynchronousPrintHandleAccessMode"=dword:00000001

 

Follow us on Twitter, http://www.twitter.com/WindowsSDK.


Comments (0)

Skip to main content