DOCUMENT:Q189617 17-JUL-1998 [vbwin] TITLE :PRB: Infinite Loop if Modal Form Shown in MDIChild's QueryUnload PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0 OPER/SYS:WINDOWS KEYWORDS: ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0 --------------------------------------------------------------------- SYMPTOMS ======== When attempting to close an MDI parent form, the application gets caught in an infinite loop of showing a modal form. CAUSE ===== When the MDI parent form is closed, the QueryUnload events of all MDI child forms are called. If any one of these MDI child forms displays a modal form during this event, such as prompting to save information, the infinite loop is initiated. This behavior will not occur if the MDI child form is closed before the MDI parent is closed. RESOLUTION ========== To work around this problem, explicitly unload the MDI child form in either the QueryUnload event of that MDI child or in the QueryUnload event of the MDI parent. STATUS ====== This behavior is by design. MORE INFORMATION ================ Steps to Reproduce Behavior --------------------------- 1. Create a new Standard EXE project. Form1 is created by default. 2. From the Project menu, add an MDI form, MDIForm1, to the project. 3. Set the MDIChild property of Form1 to True. 4. From the Project menu, add another form, Form2, to the project. 5. Paste the following code into Form1's QueryUnload event: Form2.Show vbModal 6. Run the project. 7. Attempt to close MDIForm1 without closing Form1 first. The QueryUnload event of Form1 fires in an infinite loop and Form2 is displayed repetitively. 8. Change Form1's QueryUnload event to be: Form2.Show vbModal Unload Form1 9. Repeat steps 6 and 7. The application closes as desired. Additional query words: kbDSupport kbDSD kbVBp kbVBp500 kbMDI ====================================================================== Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbprb ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.