Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Question on how to trap winform closing from VS designer

Question on how to trap winform closing from VS designer

Scheduled Pinned Locked Moved Visual Basic
visual-studioquestioncsharptutorial
14 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pravin Patil Mumbai

    Form_Closing event is definitely called buddy...Check again..

    J Offline
    J Offline
    Jon_Boy
    wrote on last edited by
    #4

    Closing is not called. When stopping the app with the "Stop Debugging" button in Visual Studio (take your flavor, 2005 or 2010) instead of closing the app through the form, the dispose, finalize and Form_closing events are bypassed. You can verify this by putting breakpoints on each and seeing if your app stops there.

    "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

    P 1 Reply Last reply
    0
    • L Luc Pattyn

      All closing and exiting events will equally fire inside or outside Visual Studio. Use one of them and take advantage of this[^]. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      J Offline
      J Offline
      Jon_Boy
      wrote on last edited by
      #5

      Hey Luc, I'm familiar with the Debugger.IsAttached because I have some debug.print statements that occur during various routines. I'm feeling rather blonde today. I created a new WinForm app from scratch in VS2010. Stuck this code in

      Private Sub Form1\_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
          MessageBox.Show("Look ma, I'm closing")
      End Sub
      

      If I start the app and close it with the X in the caption bar, woot! If I start the app and close it with the Stop Debugging button in VS on the debugging toolbar, it's just not called? Am I totally overlooking something?

      "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

      D L 2 Replies Last reply
      0
      • J Jon_Boy

        Hey Luc, I'm familiar with the Debugger.IsAttached because I have some debug.print statements that occur during various routines. I'm feeling rather blonde today. I created a new WinForm app from scratch in VS2010. Stuck this code in

        Private Sub Form1\_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            MessageBox.Show("Look ma, I'm closing")
        End Sub
        

        If I start the app and close it with the X in the caption bar, woot! If I start the app and close it with the Stop Debugging button in VS on the debugging toolbar, it's just not called? Am I totally overlooking something?

        "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #6

        Nope. When you click on Stop Debugging, your code stops, period. There is no further exectuion of your application code. So, no, there is no way to do your file cleanup from inside your application. This would have to be done seperately, from some batch of script operation you launch yourself.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        S J 2 Replies Last reply
        0
        • J Jon_Boy

          Hey Luc, I'm familiar with the Debugger.IsAttached because I have some debug.print statements that occur during various routines. I'm feeling rather blonde today. I created a new WinForm app from scratch in VS2010. Stuck this code in

          Private Sub Form1\_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
              MessageBox.Show("Look ma, I'm closing")
          End Sub
          

          If I start the app and close it with the X in the caption bar, woot! If I start the app and close it with the Stop Debugging button in VS on the debugging toolbar, it's just not called? Am I totally overlooking something?

          "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #7

          I see no solution, stopping the debug session aborts the process, without generating any of the usual events (Form.FormClosing, Application.ApplicationExit, etc). :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            Nope. When you click on Stop Debugging, your code stops, period. There is no further exectuion of your application code. So, no, there is no way to do your file cleanup from inside your application. This would have to be done seperately, from some batch of script operation you launch yourself.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            S Offline
            S Offline
            slam Iqbal
            wrote on last edited by
            #8

            I think so. my 5

            1 Reply Last reply
            0
            • J Jon_Boy

              Is it possible to tell when a WinForm app is being closed from Visual Studio when a developer uses the "Stop Debugging" button? I'd like to perform some file cleanup, etc whenever the app shuts down, but when the app is closed from VS itself vs. the close button the form, the closing, dispose, etc is not called. Just wondering if someone has run into this and what they may have done. Thanks for any suggestions or comments.

              "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

              S Offline
              S Offline
              slam Iqbal
              wrote on last edited by
              #9

              Your question is clear & Dave is correct.

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                Nope. When you click on Stop Debugging, your code stops, period. There is no further exectuion of your application code. So, no, there is no way to do your file cleanup from inside your application. This would have to be done seperately, from some batch of script operation you launch yourself.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                J Offline
                J Offline
                Jon_Boy
                wrote on last edited by
                #10

                Thanks for the answers, just wanted to make sure I wasn't overlooking something. It would be nice to have a post debug (like the pre/post build events) events, but how often would you really use them. Really hate to rely on devs. having to run a bat file or something else, because it's only human to error, but that's the only real option here. Thanks again.

                "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                M 1 Reply Last reply
                0
                • J Jon_Boy

                  Is it possible to tell when a WinForm app is being closed from Visual Studio when a developer uses the "Stop Debugging" button? I'd like to perform some file cleanup, etc whenever the app shuts down, but when the app is closed from VS itself vs. the close button the form, the closing, dispose, etc is not called. Just wondering if someone has run into this and what they may have done. Thanks for any suggestions or comments.

                  "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                  G Offline
                  G Offline
                  Gregory Gadow
                  wrote on last edited by
                  #11

                  VB makes a distinction between End and Stop, two keyworks inherited from proto-BASIC. End closes things down, fires events and cleans up memory; Stop does exactly that: stops execution and leaves the application in a suspended state that can be inspected. I believe that "Stop Debugging" is effectively the same as the Stop statement, which means that execution just... stops. If you need to test clean up code while debugging your application, you should close the application in the same way your users will close it, such as the "Close Form" button on the main form, clicking a different button, using a menu item or the like.

                  1 Reply Last reply
                  0
                  • J Jon_Boy

                    Thanks for the answers, just wanted to make sure I wasn't overlooking something. It would be nice to have a post debug (like the pre/post build events) events, but how often would you really use them. Really hate to rely on devs. having to run a bat file or something else, because it's only human to error, but that's the only real option here. Thanks again.

                    "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                    M Offline
                    M Offline
                    Mycroft Holmes
                    wrote on last edited by
                    #12

                    I assume you are trying to get back to a start up state, is it possible to move the cleanup to the aplication start process?

                    Never underestimate the power of human stupidity RAH

                    J 1 Reply Last reply
                    0
                    • M Mycroft Holmes

                      I assume you are trying to get back to a start up state, is it possible to move the cleanup to the aplication start process?

                      Never underestimate the power of human stupidity RAH

                      J Offline
                      J Offline
                      Jon_Boy
                      wrote on last edited by
                      #13

                      I have that being done already (load and form_closing), but I wanted to cover the scenario in which a developer stopped the app via stop debugging button and immediately shuts VS after that. No biggie, I'll just make it known. Kinda a special case scenario.

                      "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                      1 Reply Last reply
                      0
                      • J Jon_Boy

                        Closing is not called. When stopping the app with the "Stop Debugging" button in Visual Studio (take your flavor, 2005 or 2010) instead of closing the app through the form, the dispose, finalize and Form_closing events are bypassed. You can verify this by putting breakpoints on each and seeing if your app stops there.

                        "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                        P Offline
                        P Offline
                        Pravin Patil Mumbai
                        wrote on last edited by
                        #14

                        Let me verify it, I will get back to you..

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups