Results 1 to 2 of 2

Thread: Execute a statement while closing the win form

  1. #1

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    Execute a statement while closing the win form

    Hi,

    I have a windows application. I would like to run a statement while exiting my application. I tried adding my statement on FormClosing event. but it only executes if the application is closed properly. However, If the application is closed via task manager or system is restarted or logged out, etc. then the statement in closing or disposed event is not getting executed.

    Code:
    Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
            MsgBox("disposed")
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
            MsgBox("closing")
        End Sub
    can some one tell me how to get my statement executed even the user tries to log out or shut down or application is closed via task manger.

    Thanks
    Kanna

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Execute a statement while closing the win form

    In order to be executed, your code must be executed. If the user forcefully terminates your application in such a way that it doesn't get the opportunity to clean up then no clean up code will be executed, so there's nothing you can do. It's like if you were to close another application in code: calling Process.CloseMainWindow would allow the app to clean up but calling Process.Kill would not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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