Reputation: 2564
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?
Upvotes: 0
Views: 1784
Reputation: 2564
It seems that the issue was caused by a third party COM library. The only working solution I could find:
Private Sub MDIParentForm_Closing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If (e.CloseReason = CloseReason.UserClosing) Then
If (Not CanClose()) Then
e.Cancel = True
End If
End If
If (Not e.Cancel) Then
Process.GetCurrentProcess().Kill()
End If
End Sub
I don't like it, but it works when End doesn't.
Upvotes: 1
Reputation: 11
You may try this. Call it from your mdi formclosing perhaps the error handler will pic something up.
Private Sub CloseAllDataforms()
Dim frm As Form
' Unload all the child forms, if any.
Try
For Each frm In Me.MdiChildren
If Not frm.Name = "MDI_Main" Then
If frm.IsMdiChild = True Then
frm.Close()
frm.Dispose()
End If
End If
Next
Catch eX As Exception
Debug.Print(eX.Message.ToString())
End Try
End Sub
Upvotes: 1
Reputation: 12613
You most likely do not have all the forms of the application closed. Try this code
For Each frm as Form in My.Application.OpenForms
frm.Close
Next
It will close every form in your application.
Upvotes: 1
Reputation: 44605
this has been discussed a lot lately, is it possible you have started some threads in your application and you did not set them as Background threads?
Upvotes: 2