I have an MDI form as the app start object.
I don’t think is related, but in the Form closing event, I check for some condition, and if it’s true, I ask for confirmation before closing:
Private Sub FormBackground_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If (e.CloseReason = CloseReason.UserClosing) Then
If (conditionIsMet) Then
Dim res As DialogResult
res = MessageBox.Show("Are you sure?", "Warning", MessageBoxButtons.YesNo)
If (res <> Windows.Forms.DialogResult.Yes) Then
e.Cancel = True
End If
End If
End If
End Sub
So long, everything works fine in my development machine, which runs windows XP.
However, when deploying the application in a windows 7 machine, the message box works correctly, showing itself whenever it should, but after the form is closed the application keeps running in the background. This happens whether the form closes directly or asks the user first.
I have (hopefully) fixed it putting an End instruction in the FormBackground.FormClosed event, but it doesn’t feel good. As a workaround it’s OK for now but I’d like to find the cause of the problem.
Any thought?
It seems that the issue was caused by a third party COM library.
The only working solution I could find:
I don’t like it, but it works when End doesn’t.