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
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.