Link to home
Start Free TrialLog in
Avatar of cquinn
cquinnFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Process still running after unload

After I unload my VB6 application, running under XP, the application doesn't appear in the applications list of Task manager, but is still listedunder the pocesses tab.

I think I am unloading all of my objects and setting them to nothing, so is there any way of finding out what is causing the process to still be there?

The application uses MSAgent, CDO and a couple of OCX controls I wrote myself.
Avatar of Monchanger
Monchanger
Flag of United States of America image

Usually this happens when you miss unloading one of your forms. Try double-checking this.

Use VB.Forms to check for loaded forms.
Avatar of Sweat
Sweat

cquinn,

Monchanger is right, an ended program that is still 'running' is often the result of one or more forms not being unloaded prior to ending.

I use a simple for/next loop and unload all forms from my apps in reverse order.

    Dim rsLoop As RecordSet
    Dim i%

    On Error Resume Next
    For Each rsLoop In dbMain.Recordsets
        rsLoop.Close
        Set rsLoop = Nothing
    Next
    For i = Forms.Count - 1 To 1 Step -1
        Unload Forms(i)
    Next
    dbMain.Close
    Set dbMain = Nothing
    End

Where dbMain is my main database variable.

Sweat

It's NOT recommended but you can put End on form_unload event
I have found this can happen when the user clicks the "X" in the control box in the upper right corner instead of the "Exit" command button on the form.  To catch this, I have added the following code to each form that has a control box "X" on it:


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   If UnloadMode = 0 Then                   ' User clicked the "X" to exit
       cmdExit_Click
   End If
End Sub



Best of luck.
Hi cquinn,

Definately make sure all your forms and objects have been destroyed.  Another thing to take into consideration is if you spawn another process, you'll need to close that before your application can properly exit.

syntaX
One more thing. If you were in a loop when you decided to end, the code for the loop is still running and as a result the form the code was on (if there was one) is now reloaded into memory.  The only way I know of to stop this from happening is to put an "End" statement in the code or test for an AppUnloading global variable in the loop.
it is also possible that you are running some external process which is not yet complete when you are unloading all your forms. After the process gets completed it tries to return the control back to the application which called it. Since it cannot find the application it gives an Error something like "Automation Error"

Like For e.g. i used to face in the beginning is as below

Using the Inet control i used to access some pages. what happened was i tried to open a page which was taking a long time to load may be because of Internet connectivity. what happened is that i closed my form which was calling it & went to some other form. I got an error message saying Automation error.

I hope this helps you.

Jayesh
Avatar of cquinn

ASKER

There is only one form loaded - it is hidden and is used to allow a popup menu from an icon in the system tray.  In the Exit action of this menu, it stops a timer that was running, then starts another timer which removes the icon from the system tray, destroys all of the CDO objects I have created, then unloads the form.  Doing it with the timer prevents an known error when unloading things from the system tray.

The original timer loops through all unread messages in the inbox and uses MSAgent to read the sender and subject of any new message.

This is the code in the unloading event:

Private Sub tmrUnload_Timer()
'needs to do it this way to let the Systray unload properly
On Error GoTo ErrTrap
    tmrUnload.Enabled = False
    NotifyAgent.Hide
    NotifyAgent.Commands.RemoveAll
    Set NotifyAgent = Nothing
    MyAgent.Characters.Unload "NotifyAgent"
    Set cdoInbox = Nothing
    cdoSession.Logoff
    Set cdoSession = Nothing
    DoEvents
    Unload Me
Exit Sub
ErrTrap:
    sCurrentLocation = "Unload Timer"
    iReturn = ErrHandler(Err.Number, Err.Description, errNext, sCurrentLocation)
    Select Case iReturn
    Case errResume
        Resume
    Case errNext
        Resume Next
    Case Else
        End
    End Select

End Sub
You must unload all object and all forms in visual basic
Use following code:

Public Sub ExitProgram()
Dim iFrm as Form
For Each iFrm in Forms
Unload iFrm
Next
End
End Sub
ARMC- great to see you joining in the discussion.
Sweat already proposed the suggestion you made (it's the same idea, even though the specifics of implementation look different).
I'm sure you didn't do this on purpose, just please be careful when posting to avoid any mistunderstandings which may occur. We experts try pretty hard not to repost things said by others. It helps keep us happy and civil towards each other :-)
Although it may be a little pain staking if your form count is high, but the easiest way to ensure all forms are unloaded is,

in the form_unload of each form unload each form:

Private Sub Form_Unload(Cancel As Integer)
unload form1
unload form2
end sub


then copy the list of unload form#'s and paste in each form_unload.
Avatar of cquinn

ASKER

As I said - only a single form, which is explicitly unloaded in the code above
Can you run your task from ide
I will try to put the break pt on the form_load and form_activiate and Form_Initialize if you have any code inside there.

I believe you try to access a control that is on the form. When you try to access a control on the from, VB will start up the form first


For example

Private Sub tmrUnload_Timer()
   Unload Me
Exit Sub

You are still inside the form using the control. How can you unload your form
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to EDDYKT
Please leave any comments here within the
next seven days.
Avatar of cquinn

ASKER

Twalgrave

The suggestions have not helped me find a cure for the problem, so I would prefer to PAQ it
twalgrave,

I agree that this question needs some finalizing, however, I question the awarding of all points to the non-answer provided by EDDYKT.

cquinn indicates, after your last comment, that none of the replies has fully resolved his problem, so I think that no points should be awarded.

If, however, it is determined that cquinn must assign points, then a new review of all programmatic responses would be in order.

Sweat

Allow me to explain my reasoning on this one as it doesn't conform to my usual simple reasoning of recommendations.  cquinn was responding to the experts suggestions all along and before the last post asking it to be PAQd, had refuted all other answers until we get to EDDYKT's final posting.  So in cquinn's absence, it would appear that EDDYKT's answer helped solve the problem.  Now enter cquinn to respond to my request to clean up the question (that's why these request are made).  I'm not a moderator, so I'm not sure what they do in this circumstance, but I would presume that they would listen to cquinn's request to PAQ the question as looking at cquinn's account, abandoning questions is not the norm.  However, if cquinn has resolved the issue alone, it would be very helpful to post the solution.  If no solution has been reached, then an indication of so would help the moderators (I'm not sure if the issue is still unresolved).  Hope this clears up the why and what happens next.  The moderators will be coming by and looking at all the posts made before and after the cleanup request and will make a decision on what to do on or around 1/7/2003.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial