Solved

Application 'hangs around' after exit

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

757 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