?
Solved

Application 'hangs around' after exit

Posted on 2006-11-15
4
Medium Priority
?
690 Views
Last Modified: 2013-12-26
Hi Gurus

When a user exits my app by clicking the red close box in the top right, the app still appears in the Windows Task Manager.  If however the user goes to File, and then selects Exit, the app no longer appears in the Task Manager.

I was wondering as to what needs to happen so that my app cleanly exits, irrespective of what exit means a user has selected.

Fyi, selecting Exit from the File menu invokes the following:

Private Sub mnuFileExit_Click()
'it seems we need to keep this here (and not in the Form Unload routine above), else the app hangs
        Do Until VB.Forms.Count = 0
          Unload Forms(0)
        Loop

        Unload Me
        End
End Sub
0
Comment
Question by:BrianBeck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 17946127
What ahappens if, in your form_load or form_terminate, you simply call that sub?
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 17946227
These are the unload modes :

vb constant:      Integer:      Description:


vbFormControlMenu    0    The user chose the Close command from the 'X' on the form.
vbFormCode              1     The Unload statement is invoked from code.
vbAppWindows          2     The current Microsoft Windows operating environment session is ending
                                2      the Windows OS shuts down and closes the application

vbAppTaskManager   3     MS-Windows Task Manager is closing the application.
vbFormMDIForm       4     An MDI child form is closing because the MDI form is closing.
vbFormOwner           5     A form is closing because its owner is closing.







Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    MsgBox UnloadMode
    MsgBox (UnloadMode = vbFormControlMenu)
   
    If (UnloadMode = vbFormControlMenu) Then Call mnuFileExit_Click
End Sub



Private Sub mnuFileExit_Click()
'it seems we need to keep this here (and not in the Form Unload routine above), else the app hangs
        Do Until VB.Forms.Count = 0
          Unload Forms(0)
        Loop

        Unload Me
        End
End Sub
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 800 total points
ID: 17948036
If you have HIDDEN any other forms instead of closing them then the app will "hang around" after the main form has been closed.

Can you try this in the Form_Unload() event?

    Private Sub Form_Unload(Cancel As Integer)
        For Each frm In Forms
            Unload frm
        Next
    End Sub

And change your menu to?

    Private Sub mnuFileExit_Click()
        Unload Me
    End Sub
0
 

Author Comment

by:BrianBeck
ID: 17950085
Thanks to all contributors.

Idel Mind - thanks - Task Manager removes the app from its list when a user closes the "x" box or when they close using File/ Exit - great!
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question