Solved

Application 'hangs around' after exit

Posted on 2006-11-15
4
683 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
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 85

Accepted Solution

by:
Mike Tomlinson earned 200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now