Results 1 to 4 of 4

Thread: Closing a program

  1. #1

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    794

    Question Closing a program

    I am running WIN 7 pro with VB6. Sometimes when I close windows I forget to close any vb6 programs that are still running. This hangs the shut down process. Is there anything I can add to the program to automatically close when I shut down windows?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Closing a program

    Your Forms should be seeing QueryUnload and then Unload events. If you are not handling one or both of these events to shutdown gracefully then you'll be in trouble.

    Sitting in buzz-loops is the usual culprit that prevents these events from being handled (whether in your event handler code or if you don't have any then in the runtime).

    Of course there are other things that can cause problems too, for example circular object references.

    See:

    Visual Basic Component Shutdown Rules

    Circular References and Object Lifetime

    ... and other related articles you can find in your MSDN documentation.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Closing a program

    This probably will not solve your problem, because if your program is so pathological that it won't unload when asked to then you have some work to do. Once you have cleaned things up your problem will most likely disappear without this help.

    I have attached two projects. One is a command line application, the other is inspired by that but requires that your buzzloops pay attention and exit when they need to. And that doesn't address the possibility of other problems that keep your program from terminating when it should.

    Whatever you do, avoid the catastrophic End statement. Using that can lead to data loss and corruption that can be a far bigger headache to deal with once it happens.


    If you are already in this leaky boat, I'm not sure the code in these Projects will be very intelligible to you.
    Attached Files Attached Files

  4. #4

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    794

    Resolved Re: Closing a program

    I have solved the problem. I reviewed Dilettante's message and found that my timer was the culprit. I changed the "Form_QueryUnload" to the following.

    Code:
    Sub Form_QueryUnload(Cancel as Integer, UnloadMode As Integer)
    Cancel= True
    If UnloadMode = vbAppTaskManager Or UnloadMode = vbAppWindows then
        Unload frmDisplay
        Unload frmcondition
        End
    Else
       Unload frmCondition
       me.Hide
    End If
    End Sub
    The closing is not smooth, but it does not prevent Windows from shutting down.

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