Results 1 to 29 of 29

Thread: Program not ending

  1. #1

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

    Program not ending

    The EXE I'm running does not finish (the process is still active) in the Task Manager's list. Even after I unload all the forms and "END".

    Is there anyway to detect which object avoids it from unloading??
    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.

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

    Re: Program not ending

    Mc Brain,

    Detect the objects, no. You will have to go throught your code and make sure that when you load the object that you set it to Nothing when you are done with it.

  3. #3
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Program not ending

    Use this to exit your application:

    VB Code:
    1. For Each Form in Forms
    2.      unload Form
    3.      set form = nothing
    4. Next Form

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

    Re: Program not ending

    Here is my routine that exits a program properly, after closing all forms and releasing all objects.
    VB Code:
    1. Private Sub ExitProgram_Click()
    2.   Dim frm As Form
    3.   Dim obj As Object
    4.   If InventoryDeducted = False Then Call  CloseInv ' If Necessary !
    5.   For Each frm In Forms
    6.      If frm.Name <> Me.Name Then ' Unload this form LAST
    7.        For Each obj In frm
    8.          On Error Resume Next
    9.            Unload obj
    10.            Set obj = Nothing
    11.        Next
    12.        Unload frm
    13.        Set frm = Nothing
    14.      End If
    15.     Next
    16.     On Error Resume Next
    17.       For Each obj In frm
    18.         Unload obj
    19.         Set obj = Nothing
    20.       Next
    21.      Set frm = Nothing
    22.      Unload Me
    23. End Sub
    Last edited by dglienna; Apr 19th, 2005 at 02:27 PM.

  5. #5

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

    Re: Program not ending

    I'm already using a similar code... but it does not end.

    VB Code:
    1. Dim frm As Form
    2.    
    3.     Set Juego = Nothing
    4.     Set MessagesToServer = Nothing
    5.     Set Canto = Nothing
    6.     Set Dichos = Nothing
    7. '    Set Quejas = Nothing
    8.     Set fTablero = Nothing
    9.     Set StBy = Nothing
    10.  
    11.     Set ImgLst = Nothing
    12.     Set tFallo = Nothing
    13.  
    14.     Set OtroJuego = Nothing
    15.    
    16.     For Each frm In Forms
    17.         If frm.Name <> Me.Name Then
    18.             Unload frm
    19.             Set frm = Nothing
    20.         End If
    21.     Next
    22.  
    23.     If udpPeer.State Then udpPeer.Close
    24.    
    25.     End  'Just In Case
    What's more astonish... is that it refuses to END (see the last line of code).
    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.

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: Program not ending

    Quote Originally Posted by Mc Brain
    The EXE I'm running does not finish (the process is still active) in the Task Manager's list. Even after I unload all the forms and "END".

    Is there anyway to detect which object avoids it from unloading??
    I encountered this problem a week ago.... the problem was my Unload event code... it was accessing a form's property which resulted in the loading of that form again... I also tried using End but that didn't work as eventually the conditions which lead to End statement were becoming false in Load Event of form...

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

    Re: Program not ending

    You don't unload Me. Try using my code to see if it makes any difference.
    Are you stepping thru the code to make sure that it runs?
    Last edited by dglienna; Apr 19th, 2005 at 02:53 PM.

  8. #8

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

    Re: Program not ending

    Quote Originally Posted by dglienna
    You don't unload Me. Try using my code to see if it makes any difference.
    Are you stepping thru the code to make sure that it runs?
    A plain old END would prolly do it, though.
    I cannot step through the code... on the IDE it ends smoothly.
    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
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Program not ending

    Mc Brain,

    Search your code for any clauses like:

    Set <object> = <object>

    and make sure that these object are set to Nothing.

  10. #10

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

    Re: Program not ending

    Quote Originally Posted by moinkhan
    I encountered this problem a week ago.... the problem was my Unload event code... it was accessing a form's property which resulted in the loading of that form again... I also tried using End but that didn't work as eventually the conditions which lead to End statement were becoming false in Load Event of form...
    After the Finalizar subroutine (which code is the one I posted before)... it executes nothing!! Here's the mkcDebugger's log.

    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: frmTablero SetIcon
    *Tute v1.0.0*: Globals GetSetting
    *Tute v1.0.0*: Registry GetSettingString
    *Tute v1.0.0*: frmTablero Form_Resize
    *Tute v1.0.0*: frmTablero Form_Activate
    *Tute v1.0.0*: Globals GetSetting
    *Tute v1.0.0*: Registry GetSettingString
    *Tute v1.0.0*: frmTablero TB_ButtonClick
    *Tute v1.0.0*: frmTablero submnu_Salir_Click
    *Tute v1.0.0*: frmTablero EnRed
    *Tute v1.0.0*: frmTablero Form_QueryUnload
    *Tute v1.0.0*: frmTablero Form_Unload
    *Tute v1.0.0*: frmTablero Finalizar
    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.

  11. #11

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

    Re: Program not ending

    I don't know what happened... but it's working now.
    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.

  12. #12

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

    Re: Program not ending

    No, it doesn't!

    I don't understand what's going on. If I run this exe in my computer (W2K), it ends correctly. If I run this exe at work's computer (XP), the process does not end. What's even worse the CPU goes to 99% (for this process).

    Does anybody know what my be going on?
    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.

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

    Re: Program not ending

    Is your exe listed on the Applications or in the Processes? Sometimes I also encounter the same problem with VB6, its not listed in the applications but is listed in the processes and CPU usage really rises.....
    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

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Program not ending

    it sounds as if you maybe calling the unload from a loop, which continues after unloading all. immediately after calling unload me, try exit sub

    pete

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

    Re: Program not ending

    What does this line do?

    VB Code:
    1. If udpPeer.State Then udpPeer.Close

    Is it a winsock? Maybe that line is the beast?
    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

  16. #16

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

    Re: Program not ending

    Quote Originally Posted by dee-u
    Is your exe listed on the Applications or in the Processes? Sometimes I also encounter the same problem with VB6, its not listed in the applications but is listed in the processes and CPU usage really rises.....
    It's on both lists.
    Quote Originally Posted by westconn1
    it sounds as if you maybe calling the unload from a loop, which continues after unloading all. immediately after calling unload me, try exit sub

    pete
    Why would it work at my home's computer?
    Quote Originally Posted by dee-u
    What does this line do?

    VB Code:
    1. If udpPeer.State Then udpPeer.Close

    Is it a winsock? Maybe that line is the beast?
    It's a winsock. If it has an open port (UDP) it closes it. It's not connected with any machine, it's not TCP it is just listening to a port... just in case any other instance of the game "talks" to it.
    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.

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Program not ending

    Quote Originally Posted by Mc Brain
    After the Finalizar subroutine (which code is the one I posted before)... it executes nothing!!
    The Finalizer event? That event is only fired when there is no references left to your class or form. Try moving it to the Unload event instead.

    On a side note... I see this code all the time (several time in this thread):
    VB Code:
    1. Dim frm As Form
    2.  
    3. For Each frm In Forms
    4.     Unload frm
    5.     Set frm = Nothing
    6. Next
    Now what does the line that sets frm to Nothing do? It destroys the frm reference which will be destroyed anyway when the Next statement runs since it then references another form. Let's say I have a Form called Form2 and I use this code:
    VB Code:
    1. Dim frm As Form
    2. Form2.Load '<-- creates the Form and uses the Form2 reference
    3. Set frm = Form2 '<--- Let frm reference Form2
    In the above code I have two references to the same object. Setting frm to Nothing will destroy one of them not the origional one.

  18. #18

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

    Re: Program not ending

    Quote Originally Posted by Joacim Andersson
    The Finalizer event? That event is only fired when there is no references left to your class or form. Try moving it to the Unload event instead.
    Ok, my mistake. I should not have called it "event". It's not actually an event but a subroutine. The Finalizar subroutine gets called whenever I say so (which is in the Form_Unload).

    Quote Originally Posted by Joacim Andersson
    On a side note... I see this code all the time (several time in this thread):
    VB Code:
    1. Dim frm As Form
    2.  
    3. For Each frm In Forms
    4.     Unload frm
    5.     Set frm = Nothing
    6. Next
    Now what does the line that sets frm to Nothing do? It destroys the frm reference which will be destroyed anyway when the Next statement runs since it then references another form.
    I knew this... but I added that line (just in case). You never know what else to try.

    Quote Originally Posted by Joacim Andersson
    Let's say I have a Form called Form2 and I use this code:
    VB Code:
    1. Dim frm As Form
    2. Form2.Load '<-- creates the Form and uses the Form2 reference
    3. Set frm = Form2 '<--- Let frm reference Form2
    In the above code I have two references to the same object. Setting frm to Nothing will destroy one of them not the origional one.
    Actually, I think you have a loaded form and a reference (pointer) to it. This code:

    VB Code:
    1. Option Explicit
    2.  
    3. Private frm As Form
    4.  
    5. Private Sub Command1_Click()
    6.     Unload frm
    7.     Set frm = Nothing
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11.     Load Form2 '<-- creates the Form and uses the Form2 reference
    12.     Form2.Show
    13.     Set frm = Form2 '<--- Let frm reference Form2
    14. End Sub

    would close the only Form2 loaded and then point to nothing. Anyway, I still don't understand where you're trying to get.
    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.

  19. #19
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Program not ending

    In your example you set frm to nothing but you don't set Form2 to nothing. Both of those object pointers or references exist, setting one to nothing but not the other is about the same thing as you don't put any to nothing.

  20. #20
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Program not ending

    Anyhow... Try moving the line that closes the winsock to before you start unloading each form.

  21. #21

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

    Re: Program not ending

    Quote Originally Posted by Joacim Andersson
    In your example you set frm to nothing but you don't set Form2 to nothing. Both of those object pointers or references exist, setting one to nothing but not the other is about the same thing as you don't put any to nothing.
    Isn't that what Unload Form2 is for?
    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.

  22. #22

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

    Re: Program not ending

    Quote Originally Posted by Joacim Andersson
    Anyhow... Try moving the line that closes the winsock to before you start unloading each form.
    Wow!! How didn't I realize of that before. Anyway, I did move the line (which is safer), but still not closing.
    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.

  23. #23
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Program not ending

    Quote Originally Posted by Mc Brain
    Isn't that what Unload Form2 is for?
    Unload Form2 will unload the visual parts of the form. It will not unload the code itself. Why would you set the reference to Nothing if it was OK to just unload it (which it is in most cases).

  24. #24

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

    Re: Program not ending

    Quote Originally Posted by Joacim Andersson
    Unload Form2 will unload the visual parts of the form. It will not unload the code itself. Why would you set the reference to Nothing if it was OK to just unload it (which it is in most cases).
    I don't know. I also don't know why we're discussing about an example or about something that is not needed instead of what should be changed or added in the real code.
    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.

  25. #25
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Program not ending

    Quote Originally Posted by Mc Brain
    I also don't know why we're discussing about an example or about something that is not needed
    Well, as I mentioned in my origional apply:
    Quote Originally Posted by Joacim Andersson
    On a side note... I see this code all the time
    The key word here is On a side note.... Nothing to do with your question at all so let's not get ourself stuck on that issue.

    I do understand that posting your project would be a lot to ask for but I it would be very helpful to be able to see this behaviour with my own (bug seeking ) eyes.

  26. #26

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

    Re: Program not ending

    Quote Originally Posted by Joacim Andersson
    I do understand that posting your project would be a lot to ask for but I it would be very helpful to be able to see this behaviour with my own (bug seeking ) eyes.
    Yes, it does. It's a 90% working net-game... and would not like anyone on this planet be able to download the whole code.

    Whenever I finishs it, I will consider releasing its code... but it does not outlook so good right now.


    Edit: What the h... was "net-working game"? Were you high??? I'm not fan with "working net-game" either, but I guess it explains better
    Last edited by Mc Brain; May 1st, 2005 at 09:09 AM.
    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.

  27. #27

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

    Re: Program not ending

    I think "End" was the problem. I remove the "just in case" End... and the process removed itself from memory as if everything was correctly deleted.

    VB Code:
    1. Private Sub Finalizar()
    2.     If mkcDebug Then DebugPrint "frmTablero   Finalizar"
    3.  
    4.     Dim frm As Form
    5.    
    6.     Set Juego = Nothing
    7.     Set MessagesToServer = Nothing
    8.     Set Canto = Nothing
    9.     Set Dichos = Nothing
    10. '    Set Quejas = Nothing
    11.     Set fTablero = Nothing
    12.     Set StBy = Nothing
    13.     Set MessageIDHistory = Nothing
    14.  
    15.     Set ImgLst = Nothing
    16.     Set tFallo = Nothing
    17.  
    18.     Set OtroJuego = Nothing
    19.    
    20.     If udpPeer.State Then udpPeer.Close
    21.    
    22.     For Each frm In Forms
    23.         Unload frm
    24.         Set frm = Nothing
    25.     Next
    26.    
    27.     'End  'Just In Case
    28.    
    29.     If mkcDebug Then DebugPrint "frmTablero   Finalizar - Out"
    30. End Sub
    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.

  28. #28
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

    Re: Program not ending

    Are you using multithread? I guess sme threads are not quiting.



  29. #29

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

    Re: Program not ending

    Quote Originally Posted by temp_12000
    Are you using multithread? I guess sme threads are not quiting.
    It's finishing correctly now.
    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.

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