I am having trouble closing a form. Here is the scenario:

'------------- Code Sample ------------
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
Me.Visible = False
End Sub
'--------------------------------------

When the form Close button is clicked, the form closing event is cancelled and the form is minimized to the Notification area. The user can exit the program by selecting the appropriate menu option. This all works as it should.

The problem arises when Windows attempts to close the program when shutting down or restarting Windows.

How can i differentiate between a user clicking the form Close button and the system trying to close the application?