Results 1 to 37 of 37

Thread: [RESOLVED] exe still running after been closed?

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Resolved [RESOLVED] exe still running after been closed?

    i created an exe with multiple forms but when you close it down it still stays running in the task manager. any idea whats causing this?

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: exe still running after been closed?

    your not unlaoding your forms, and objects

    tell us what your app is, whats controls it contains etc

    Pino

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: exe still running after been closed?

    This is what it's called "Memory leak". There are objects or even entire form(s) which were not unloaded from memory. You should never use the END instruction to finish your application. Be sure you unload all the forms, and destroy each object you've loaded into memory. Once you've done this... your program will just end pacefully.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    erm its a login/register form

    theres 4 forms, main menu, login form, register form. and a terms and conditions form.

    starts on main menu, theres 2 radio buttons and a command buttong. dpending on what radio button is choosen the login or register form will open. and the terms and conditions form loads by clicking on a label on the register form...sorry im rubbish at explaining...

  5. #5
    Addicted Member
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    135

    Re: exe still running after been closed?

    Put this in your Unload event:
    Code:
        Dim Form As Form
           
        For Each Form In Forms
            Unload Form
        Next

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: exe still running after been closed?

    Quote Originally Posted by ultimate165
    erm its a login/register form

    theres 4 forms, main menu, login form, register form. and a terms and conditions form.

    starts on main menu, theres 2 radio buttons and a command buttong. dpending on what radio button is choosen the login or register form will open. and the terms and conditions form loads by clicking on a label on the register form...sorry im rubbish at explaining...
    your not rubbish, if its simple could you post me yor app? as has been stated you may be using END which is bad practice.

    Pino

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    do i put that exact code?...

  8. #8
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: exe still running after been closed?

    Here you have a thread to shed some light on you. You might learn some interesting things out of this thread.

    http://www.vbforums.com/showthread.p...hlight=in+case
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: exe still running after been closed?

    could you zip up all of your project files, and uplaod it.

    Pino

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    Quote Originally Posted by Pino
    your not rubbish, if its simple could you post me yor app? as has been stated you may be using END which is bad practice.

    Pino
    i didnt have any end i just closed the app using the X lol
    edit: where do i upload to? its only 5kbs

  11. #11

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    nope still cant get it done.

    it works for the main form but i cant get the others unloaded

    if anyone has msn contact me on [email protected] and ill send you over the files so you can show me what to do thanks
    Last edited by ultimate165; Nov 25th, 2005 at 04:20 PM.

  12. #12

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    still cant fix it

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: exe still running after been closed?

    You really shouldn't post your email address since spammers can pick it up.

    It's been suggested that you create a zip file and upload it here so we can take a look at it. If you can create a zip (or rar) file then just click the Manage Attachments button and it will help you complete the upload.

  14. #14
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: exe still running after been closed?

    Quote Originally Posted by ultimate165
    i didnt have any end i just closed the app using the X lol
    edit: where do i upload to? its only 5kbs
    When you are composing your reply you'll see a Manage Attachment below where you are typing...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  15. #15

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    thanks for that. well theres the files. has all the forms and everything so if someone could correct my mistakes and tell me what im doing wrong so i can understand it, it will save me goin wrong in the future. thanks
    Attached Files Attached Files

  16. #16
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: exe still running after been closed?

    Instead of Unload Form use Unload Me instead...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  17. #17

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    ok thanks. do i just put Unload Me in the same place i had all the unload form stuff?

    damn this is frustrating. can anyone at all point me in the right direction and explain what i need to do and explain how it works?
    Last edited by ultimate165; Nov 26th, 2005 at 12:11 PM.

  18. #18
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: exe still running after been closed?

    ok, what is happening is when you close your app your app isnt unloading all of its 'bits' this is why it is still appearing in your task menu.

    The simple way to solve this is to unlaod all the forms manually. using a very simple loop here.

    VB Code:
    1. Dim Form As Form
    2.        
    3.     For Each Form In Forms
    4.         Unload Form
    5.     Next

    'Taken from above post

    or you can simply put the following statement in all of your forms unlaod events

    VB Code:
    1. Unload Me

    now all you need to do is add that to each of your form_unload events, and its should be ok.

    I'd fix it but i havent insatlled Vb6 on this machine since i re-formated .Net is taking over

    Hope that helps

  19. #19

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    thanks ill give it a go now... ive been putting the code into the exitprogram part

  20. #20

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    [QUOTE=Pino]
    VB Code:
    1. Dim Form As Form
    2.        
    3.     For Each Form In Forms
    4.         Unload Form
    5.     Next


    ok where do i put this code? ive put it at the top of the code in declarations and nothing, ive also tried putting it in the form_unload() part but i get compile errors

    and ive tried

    Private Sub Form_UnLoad()
    Unload Me
    End Sub

    but i get an error saying "procedual declaration does not match description of event or procedure having the same name" which is problyc cause i dont have a button that unloads the form. i just want to end the program by closing it using the X at the top of the window
    Last edited by ultimate165; Nov 26th, 2005 at 02:04 PM.

  21. #21
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: exe still running after been closed?

    I have a command button that gets clicked to end the app. Here is the code for the module

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdExit_Click()
    4.  Dim frm As Form
    5.  For Each frm In Forms
    6.    If frm.Name <> Me.Name Then ' Unload this form LAST
    7.      Unload frm
    8.      Set frm = Nothing
    9.    End If
    10.  Next
    11.  Unload Me
    12. End Sub

  22. #22
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: exe still running after been closed?

    Sorry Pino but putting Unload Me in the form's Unload event isn't going to do anything since at that point the form is already unloading. Here is what you want to do. Put the following code in each forms QueryUnload event

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    VB Code:
    1. Dim frm As Form
    2.    
    3.     For Each frm In Forms
    4.         If frm.Name <> Me.Name Then
    5.             Unload frm
    6.             Set frm = Nothing
    7.         End If
    8.     Next
    9.    
    10.     Unload Me
    11.     Set Form2 = Nothing ' Form2 should be changed to the name of the form where the code is

    Or better yet add the following sub to a code module.

    VB Code:
    1. Public Sub UnloadAllForms(AForm As Form)
    2.    
    3.     Dim frm As Form
    4.    
    5.     For Each frm In Forms
    6.         If frm.Name <> AForm.Name Then
    7.             Unload frm
    8.             Set frm = Nothing
    9.         End If
    10.     Next
    11.    
    12.     Unload AForm
    13.     Set AForm = Nothing
    14.  
    15. End Sub
    and call it from each form's QueryUnload event like this

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.  
    3.     UnloadAllForms Me
    4.    
    5. End Sub

  23. #23
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: exe still running after been closed?

    Actually, This is redundant since the form is already being unloaded in the unload event
    VB Code:
    1. Unload AForm
    2.     Set AForm = Nothing

  24. #24

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    im getting so confused

    heres the forms i have and everything can someone look thru them and just tell me what i should take out and what i should put in? thanks
    Attached Files Attached Files

  25. #25
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: exe still running after been closed?

    Quote Originally Posted by ultimate165
    im getting so confused

    heres the forms i have and everything can someone look thru them and just tell me what i should take out and what i should put in? thanks
    I'm not surprised. Every time someone asks about closing forms (which is actually a very simple process) several people always chime in and often split hairs about what is right and what isn't which can be very confusing. So don't feel bad, it's not you, it's us.

    I can't open rar files but if you can create a zip file I could help more.

  26. #26

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    ok heres a zip...
    Attached Files Attached Files

  27. #27

  28. #28
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: exe still running after been closed?

    You should start the code in Sub Main() in a module. Change the startup form to sub Main in project properties.

    Then, in Sub Main, you would allow the user to log in. If he passes the login, you would load the next form. If he fails the login, then you don't do anything, and nothing is shown. Then, you only have to worry about the main form unloading.

    Here is what I do. I give them 4 chances to get it right:

    VB Code:
    1. Sub Main()
    2.   LoginSucceeded = False
    3.   Do Until LoginSucceeded = True Or lcnt = 4
    4.     frmLogin.Show vbModal
    5.   Loop
    6.   If LoginSucceeded = True Then
    7.     frmMain.Show
    8.   End If
    9. End Sub

    Also, the screens didn't look right at 1024x768 resolution.

  29. #29

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    wow thanks. it seems to work now the only thing is i dont understand what i was doing wrong?

    also the reason the interface may of looked funny was because i was using a custom font... how to i make it so other people get the custom font downloaded to thier font folder when they open up the program?

    or better still be able to view the font without them downloading it

  30. #30
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: exe still running after been closed?

    Basically there was something that was still in memory and wasn't unloaded. Lets take the smallest possible example:

    - you have two forms, Form1 and Form2
    - Form2 is opened from Form1
    - Form2 has a button with code Me.Hide
    - clicking this button will hide Form2, but not unload it
    - you close Form1
    - program stays open, because Form2 is still in memory although you can't see it

    And the end result is that the program doesn't close. This is the case every time a program doesn't end properly: something is still in memory.

    Another common mistake:

    VB Code:
    1. Private Sub cmdClose_Click()
    2.     Unload Me
    3.     SaveFile Text1.Text
    4. End Sub

    The problem here is that the form is unloaded once, but when you call Text1, the form is reloaded into the memory. And so the program doesn't end.

  31. #31
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: exe still running after been closed?

    To properly unload all forms and allow your program to terminate follow these simply rules (and code)

    in a Module place this code
    VB Code:
    1. Public Sub UnloadAll(Optional activefrm As Form)
    2.  
    3. Dim frm As Form
    4. Dim ctl As Control
    5.  
    6.     On Error Resume Next
    7.    
    8.     For Each frm In Forms
    9.    
    10.         ' Don't unload active form or we will reload it when we return to it
    11.         ' Allow active form to unload itself
    12.  
    13.         If frm.Name <> activefrm.Name Then
    14.  
    15.             ' This is extra protection and may not be needed
    16.  
    17.             For Each ctl In frm.Controls  
    18.                 Set ctl = Nothing
    19.             Next
    20.  
    21.             Unload frm
    22.             Set frm = Nothing
    23.  
    24.         End If
    25.  
    26.     Next
    27.  
    28. End Sub
    29.  
    30. ' In your main form include this call in your Unload event (Not the Query_Unload Event)
    31.  
    32. UnloadAll Me
    33.  
    34. ' If you start your program from Sub Main just use this code at the end of your mainline code
    35.  
    36. UnloadAll

    And thats it!!! Your program will unload all forms and allow your program to terminate.
    Last edited by randem; Nov 26th, 2005 at 02:56 PM.

  32. #32
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: exe still running after been closed?

    You have to include and install custom fonts if you use them in your app. I think Inno does it for you, but I'm not sure.

  33. #33

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    Quote Originally Posted by dglienna
    You have to include and install custom fonts if you use them in your app. I think Inno does it for you, but I'm not sure.
    but how do i get them to install on someone elses computer when they open up the application? dont understand any of this stuff lol

  34. #34
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: exe still running after been closed?

    This is why he suggested to make a setup program (InnoSetup creates installation programs).

    Though admittedly he forgot to mention the word "setup"

  35. #35
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: exe still running after been closed?

    ultimate165,

    You actually have to do some of the reasearch, believe it or not...

    Read the help section of Inno Setup on Font Installation.

  36. #36

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    46

    Re: exe still running after been closed?

    hehe ok. ill go and get inno "setup" now

  37. #37
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: exe still running after been closed?

    I left off the word Setup because there is Inno Setup and Inno Script, which writes the code for Inno Setup.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width