Application Ecit In Win Forms 2.0

G

Guest

All,
I'm getting this exception error when I attempt to exit out a Win Forms 2.0
application with the following sample code:
Private Sub RaythomConfiguration_FormClosing(ByVal sender As Object,
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MsgBox("Are You Sure You Want To Close?", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
Me.Dispose()
Else
e.Cancel = System.Windows.Forms.DialogResult.No
End If
End Sub


Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncancel.Click
Me.Close()
End Sub

Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnexit.Click
Application.Exit()
End Sub

The eror message is as follows:
System.InvalidOperationException was unhandled
Message="Collection was modified; enumeration operation may not execute."
Source="mscorlib"

How do I exit out when i'm using the Form_Closing sub routine? Any help
would be greatly appreciated?

Thanks,
 
B

Brian P. Hammer

I think if you remove me.dispose, you should be okay. If you are trying to
close the entire app, use application.exit.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top