Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Who terminated my app? 1

Status
Not open for further replies.

mrdance

Programmer
Apr 17, 2001
308
SE
I wonder if there is a way to see if Windows terminated the application when the user tried to shutdown or if the user clicked on the X int the application.

thanks / Henrik

--- neteject.com - Internet Solutions ---
 
An option?

You could create a log file that is written to when the user exits the application gracefully OR clicks the "X". This way you would know if the application died on purpose or not. Do you need the code to know if the user clicked the "X"?

sm
 
Yes, I need to know if the user clicked on X. How can I tell that?

thanks / Henrik

--- neteject.com - Internet Solutions ---
 
I dont see how smeeks solution does not work for you. According to your post, the user may only exit with clicking the x, or shutting down the PC.
 
I am sorry for the misunderstanding. When exiting my application I show a message box saying "Are you sure you want to exit?". The user can answer yes or no. That's fine. But I don't want to show this messagebox when the user shut downs the pc (windows is trying to terminate the app).

So my question is, how do I know when the user clicks on exit and when windows shut down the app? Is there a certain click event that the user fires but windows don't?

thanks / Henrik

--- neteject.com - Internet Solutions ---
 
This should work

Code:
    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If sender Is Me Then
            'insert code for when user clicks the close button
        Else
            'insert code for any other situation
        End If
    End Sub
 
I am sorry, when I tried to implement your solution it didn't work. On shutdown, the sender is the form as if you clicked exit. Any other ideas?

thanks / Henrik

--- neteject.com - Internet Solutions ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top