Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Windows Vista - Application hangs upon exit if print dialog is open


View products that this article applies to.

Symptoms

When an application opens two unrelated visible windows, and the main window invokes the Print dialog, the application may hang when terminating. This can occur under the following conditions:

1. An application opens two or more unrelated visible windows.
2. The main window invokes a Print dialog.
3. The main window does not destroy the other windows on receipt of WM_DESTROY.
4. The user attempts to exit the application by closing the main window.

↑ Back to the top


Cause

PrintUI uses classes which communicate across threads using events. For a typical register\unregister communication, one raises an event to another thread and waits for a handshake. This wait is indefinite and results in a hang if the other trhread was somehow terminated. Application termination results in the killing of all threads other than the executing thread. The executing thread performs COM uninitialization, which triggers a PrintUI object to communicate with its corresponding thread. However, all threads having terminated, the executing thread waits indefinitely resulting in a hang.

↑ Back to the top


Workaround

1. Specifically close all windows when responding to WM_DESTROY. This cleanup of all other windows before exit() ensures that only one window exists when the application terminates.

2. Make all additional windows children of the main window.

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2616023
Revision : 1
Created on : 1/7/2017
Published on : 9/6/2011
Exists online : False
Views : 203