Results 1 to 11 of 11

Thread: Application not Closing on Close Window

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Question Application not Closing on Close Window

    I have noticed that if you close down a form by using "Close Window" in the Task Bar, then it does not actually close the application - it puts it running as a "Background Process" if you look in Task Manager!

    You can get round this by intercepting the Form Closing event:
    Code:
    Private Sub frmMyForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
      End
    End Sub
    So, is this a fault or a feature?

    I have lots of forms so can I do something somehwere that would look like this?
    Code:
    Private Sub FormMaster(sender As Object, e As FormClosingEventArgs) Handles _
      MyForm01.FormClosing,
      MyForm02.FormClosing,
      MyForm03.FormClosing,
      MyForm04.FormClosing
    
      End
    End Sub
    Many thanks in advance ...

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: Application not Closing on Close Window

    What is the relationship between the forms? How is Shutdown mode in the projects properties set?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Re: Application not Closing on Close Window

    Quote Originally Posted by dbasnett View Post
    What is the relationship between the forms? How is Shutdown mode in the projects properties set?
    The app starts in Main() - because it uses command line arguments etc - so looks like I cannot set the Shutdown Mode?

  4. #4
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Application not Closing on Close Window

    Try using this:
    Code:
        Protected Overrides Sub Finalize()
            GC.Collect()
            System.Windows.Forms.Application.Exit()
            System.Environment.Exit(0)
            MyBase.Finalize()
        End Sub
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Re: Application not Closing on Close Window

    Quote Originally Posted by TDQWERTY View Post
    Try using this:
    Code:
        Protected Overrides Sub Finalize()
            GC.Collect()
            System.Windows.Forms.Application.Exit()
            System.Environment.Exit(0)
            MyBase.Finalize()
        End Sub
    Brilliant! It works when put into the actual form but that means having it appear lots of times (once for each form). Is there a way round that?

  6. #6
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Application not Closing on Close Window

    Using End is not a good idea you should be using Me.Dispose instead to properly dispose of any class including forms.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Application not Closing on Close Window

    So, you turned off the application framework, and are running into some issues. Since you are using forms, why turn off the application framework? What are you gaining other than making things a bit more awkward?
    My usual boring signature: Nothing

  8. #8
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Application not Closing on Close Window

    Quote Originally Posted by wavering View Post
    The app starts in Main() - because it uses command line arguments etc - so looks like I cannot set the Shutdown Mode?
    You can take command line arguments with the Application Framework enabled.

    At the bottom of the Project Application tab, select Application Events. One of the application events is the startup event, which will contain the command line arguments as part of that method parameter.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Re: Application not Closing on Close Window

    Quote Originally Posted by Shaggy Hiker View Post
    So, you turned off the application framework, and are running into some issues. Since you are using forms, why turn off the application framework? What are you gaining other than making things a bit more awkward?
    Well, see Screen Shot below ... !
    Attached Images Attached Images  

  10. #10
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Application not Closing on Close Window

    Make the startup object a form.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  11. #11
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Application not Closing on Close Window

    if you used end no way it's still running.

Tags for this Thread

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