Solved

VB6 application's process continues running after application closes

Posted on 2008-10-30
4
740 Views
Last Modified: 2013-12-26
My VB6 application continues to run indefinitely as a process after the application closes.  The phantom process uses 0 cpu but it takes up memory and ties up the .exe file as being in-use.  The task manager doesn't show it listed as applications but it does show it in the process list.

I added "EndProcess(function shown below) programname.exe" at the start of the program to kill any processes leftover from any previous executions.  Prior to that line of code, more and more phantom processes would appear in the process list each time the program ran. This line of code prevents the accumulation of phantom processes but I still can't get rid of the process that remains after the program finishes.  This problem only occurs when running the .exe.  When I run it in the IDE, it doesn't leave any processes running after it ends.

It looks to me through tracing in the IDE and msgboxes that all of the forms are being unloaded.  Shouldn't that clear out all of the memory and kill the application and process when the final form is unloaded?  I dynamically create a few controls while the program is running, are they removed from memory when the form is unloaded?  I also define some variables as public in a module.  Are the module's variables removed from memory when the final form is unloaded?  How can I determine what is remaining resident in memory after the program runs?  

Public Function EndProcess(ByVal sExeName As String) As Boolean
' This works at the beginning of the program to end any processes that are still running since the last time this program ran
   On Error GoTo Err_Handler  
   Dim oProcessCollection, oProcess, ok, ii
   Set oProcessCollection = GetObject("WinMgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & sExeName & "'")   
   ii = oProcessCollection.Count
   Debug.Print "Total: " & ii   
   If oProcessCollection.Count > 1 Then
      For Each oProcess In oProcessCollection
         ok = (oProcess.Terminate = 0)
         If ok Then
            ii = ii - 1
            Debug.Print "Count: " & ii
            If ii = 1 Then
               Exit For
            End If
         End If
      Next
   End If   
   Exit Function
Err_Handler:
   Debug.Print Err.Description
   EndProcess = False
End Function

Open in new window

0
Comment
Question by:SteveQ2
[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 86

Expert Comment

by:Mike Tomlinson
ID: 22843584
Do you have any "infinite processing loops" in your app with DoEvents() within to keep the app responsive?

What does your app do?
0
 
LVL 2

Expert Comment

by:vbsquickresponse
ID: 22843628
This generally happen when unhandled object exists in memory, cause program not to terminate properly....

I suggest you to check if any - late binding object in project are handled properly? Or any form object not closed before user try to close application!

-------------
 I dynamically create a few controls while the program is running, are they removed from memory when the form is unloaded?   - Yes
I also define some variables as public in a module.  Are the module's variables removed from memory when the final form is unloaded?  - Yes
0
 
LVL 10

Accepted Solution

by:
peetm earned 500 total points
ID: 22844343
Not a 'debug', but you could just call 'End' in the main form's Unload event!
0
 

Author Closing Comment

by:SteveQ2
ID: 31511772
I would love to know what is really causing the leftover process after the program finishes; but your suggestion seems to be a good quick fix.  Thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

690 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