VB.net集合被修改;枚举操作可能无法执行错误
我收到一个集合已修改;每次我尝试关闭此表单时,枚举操作可能无法执行错误。我怀疑它与我在起始表单(Details1)中声明的 StringBuilder() 有关。我已经花了几个小时寻找问题。当我调试时它不会抛出错误,只有当我在其他机器上安装时才会抛出错误。
请帮忙。
> Public Class PLocation
>
> Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
> Label2.Text = ""
> Dim showForm As Form = My.Settings.PreviousForm
> showForm.Show()
> Me.Hide()
> End Sub
>
> Private Sub PLocation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
> Label2.Text = ""
> Label1.Text = My.Settings.CurrentProject1
> Label6.Text = My.Settings.UserInitials1
> Label5.Text = My.Settings.CurrentDataPath1
> Label7.Text = My.Settings.EquipID1
> Label8.Text = My.Settings.CurrentPunchItem1
> Home.Details1.Clear()
>
> End Sub
>
> Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
> Dim ExitBox As MsgBoxResult = MessageBox.Show("Are you sure you want to CLOSE this program?", _
> "WARNING", _
> MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
>
> 'If Yes, then delete
> If ExitBox = MsgBoxResult.Yes Then
> Home.Close()
>
> End If
> End Sub
>
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
> If TextBox1.Text.Contains(",") Then
> Label2.Text = "Remove commas in comment box."
> Else
> Label2.Text = ""
> If CheckBox1.Checked Then
> Home.Details1.Append("Breakover; ")
> End If
>
> If CheckBox2.Checked Then
> Home.Details1.Append("Chute; ")
> End If
>
> If CheckBox3.Checked Then
> Home.Details1.Append("Drive pulley; ")
> End If
>
> If CheckBox4.Checked Then
> Home.Details1.Append("End pulley; ")
> End If
> If CheckBox5.Checked Then
> Home.Details1.Append("Return roller; ")
> End If
> If CheckBox6.Checked Then
> Home.Details1.Append("Sideguard; ")
> End If
> If CheckBox7.Checked Then
> Home.Details1.Append("Slider bed; ")
> End If
> If CheckBox8.Checked Then
> Home.Details1.Append("Snub; ")
> End If
> If CheckBox9.Checked Then
> Home.Details1.Append("Take-up; ")
> End If
> If CheckBox10.Checked Then
> Home.Details1.Append("Head end; ")
> End If
> If CheckBox11.Checked Then
> Home.Details1.Append("Tail end; ")
> End If
> If CheckBox12.Checked Then
> Home.Details1.Append("Drive section; ")
> End If
> If CheckBox13.Checked Then
> Home.Details1.Append("Middle; ")
> End If
> If CheckBox14.Checked Then
> Home.Details1.Append("Left side; ")
> End If
> If CheckBox15.Checked Then
> Home.Details1.Append("Right side; ")
> End If
> If CheckBox16.Checked Then
> Home.Details1.Append("at joint ; ")
> End If
> If CheckBox17.Checked Then
> Home.Details1.Append("Top side; ")
> End If
> If CheckBox18.Checked Then
> Home.Details1.Append("Bottom side; ")
> End If
> If CheckBox19.Checked Then
> Home.Details1.Append("Insider / Inner; ")
> End If
> If CheckBox20.Checked Then
> Home.Details1.Append("Outside / Outer; ")
> End If
> If CheckBox21.Checked Then
> Home.Details1.Append("Above; ")
> End If
> If CheckBox22.Checked Then
> Home.Details1.Append("Below; ")
> End If
> If CheckBox23.Checked Then
> Home.Details1.Append("Lower; ")
> End If
> If CheckBox24.Checked Then
> Home.Details1.Append("Upper; ")
> End If
> If CheckBox27.Checked Then
> Home.Details1.Append("Bad installation; ")
> End If
> If CheckBox28.Checked Then
> Home.Details1.Append("Bent; ")
> End If
> If CheckBox29.Checked Then
> Home.Details1.Append("Damaged; ")
> End If
> If CheckBox30.Checked Then
> Home.Details1.Append("Dented; ")
> End If
> If CheckBox31.Checked Then
> Home.Details1.Append("Gap; ")
> End If
> If CheckBox32.Checked Then
> Home.Details1.Append("Incomplete; ")
> End If
> If CheckBox33.Checked Then
> Home.Details1.Append("Insufficient; ")
> End If
> If CheckBox34.Checked Then
> Home.Details1.Append("Loose; ")
> End If
> If CheckBox35.Checked Then
> Home.Details1.Append("Misaligned; ")
> End If
> If CheckBox36.Checked Then
> Home.Details1.Append("No access; ")
> End If
> If CheckBox37.Checked Then
> Home.Details1.Append("Uneven; ")
> End If
> If CheckBox38.Checked Then
> Home.Details1.Append("Not installed; ")
> End If
> If CheckBox39.Checked Then
> Home.Details1.Append("Not straight; ")
> End If
> If CheckBox40.Checked Then
> Home.Details1.Append("Rusted; ")
> End If
> If CheckBox41.Checked Then
> Home.Details1.Append("Sharp edges; ")
> End If
> If CheckBox42.Checked Then
> Home.Details1.Append("Too large; ")
> End If
> If CheckBox43.Checked Then
> Home.Details1.Append("Too long; ")
> End If
> If CheckBox44.Checked Then
> Home.Details1.Append("Too short; ")
> End If
> If CheckBox45.Checked Then
> Home.Details1.Append("Too Small; ")
> End If
> If CheckBox46.Checked Then
> Home.Details1.Append("Wrong type; ")
> End If
> If CheckBox47.Checked Then
> Home.Details1.Append("Wrong color; ")
> End If
> If CheckBox48.Checked Then
> Home.Details1.Append("Wrong size; ")
> End If
> If CheckBox25.Checked Then
> Home.Details1.Append("times 2; ")
> End If
> If CheckBox26.Checked Then
> Home.Details1.Append("times 3; ")
> End If
> If TextBox1.Text = "" Then
> 'do nothing
> Else
> Home.Details1.Append(", " & TextBox1.Text)
> End If
>
> Home.Details2 = Home.Details1.ToString
> Summary.Show()
> Me.Close()
>
> End If
> End Sub
>
>
>
> Private Sub Label16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
> About.Show()
> End Sub
>
>
> End Class
>
***** 异常文本 ******* System.InvalidOperationException:集合已修改;枚举 操作可能无法执行。在 System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource 资源)位于 System.Collections.Generic.List
1.Enumerator.MoveNextRare() 位于 System.Collections.Generic.List
1.Enumerator.MoveNext() 位于 Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(布尔值 处置)于 Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(布尔值 处置)在 System.ComponentModel.Component.Dispose() 处 System.Windows.Forms.Control.Dispose(布尔处置)位于 System.Windows.Forms.Form.Dispose(布尔处置)位于 WindowsApplication1.PLocation.Dispose(布尔处置)位于 System.ComponentModel.Component.Dispose() 位于 System.Windows.Forms.Form.WmClose(Message&m) at System.Windows.Forms.Form.WndProc(Message&m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg、IntPtr wparam、IntPtr lparam)
I'm getting a Collection was modified; enumeration operation may not execute error every time I try to close this form. I suspect it has something to do with the StringBuilder() which I have declared in the starting form (Details1). I have already spent hours looking for the problem. It does not throw an error when I debug, only when I install on other machines.
Please help.
> Public Class PLocation
>
> Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
> Label2.Text = ""
> Dim showForm As Form = My.Settings.PreviousForm
> showForm.Show()
> Me.Hide()
> End Sub
>
> Private Sub PLocation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
> Label2.Text = ""
> Label1.Text = My.Settings.CurrentProject1
> Label6.Text = My.Settings.UserInitials1
> Label5.Text = My.Settings.CurrentDataPath1
> Label7.Text = My.Settings.EquipID1
> Label8.Text = My.Settings.CurrentPunchItem1
> Home.Details1.Clear()
>
> End Sub
>
> Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
> Dim ExitBox As MsgBoxResult = MessageBox.Show("Are you sure you want to CLOSE this program?", _
> "WARNING", _
> MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
>
> 'If Yes, then delete
> If ExitBox = MsgBoxResult.Yes Then
> Home.Close()
>
> End If
> End Sub
>
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
> If TextBox1.Text.Contains(",") Then
> Label2.Text = "Remove commas in comment box."
> Else
> Label2.Text = ""
> If CheckBox1.Checked Then
> Home.Details1.Append("Breakover; ")
> End If
>
> If CheckBox2.Checked Then
> Home.Details1.Append("Chute; ")
> End If
>
> If CheckBox3.Checked Then
> Home.Details1.Append("Drive pulley; ")
> End If
>
> If CheckBox4.Checked Then
> Home.Details1.Append("End pulley; ")
> End If
> If CheckBox5.Checked Then
> Home.Details1.Append("Return roller; ")
> End If
> If CheckBox6.Checked Then
> Home.Details1.Append("Sideguard; ")
> End If
> If CheckBox7.Checked Then
> Home.Details1.Append("Slider bed; ")
> End If
> If CheckBox8.Checked Then
> Home.Details1.Append("Snub; ")
> End If
> If CheckBox9.Checked Then
> Home.Details1.Append("Take-up; ")
> End If
> If CheckBox10.Checked Then
> Home.Details1.Append("Head end; ")
> End If
> If CheckBox11.Checked Then
> Home.Details1.Append("Tail end; ")
> End If
> If CheckBox12.Checked Then
> Home.Details1.Append("Drive section; ")
> End If
> If CheckBox13.Checked Then
> Home.Details1.Append("Middle; ")
> End If
> If CheckBox14.Checked Then
> Home.Details1.Append("Left side; ")
> End If
> If CheckBox15.Checked Then
> Home.Details1.Append("Right side; ")
> End If
> If CheckBox16.Checked Then
> Home.Details1.Append("at joint ; ")
> End If
> If CheckBox17.Checked Then
> Home.Details1.Append("Top side; ")
> End If
> If CheckBox18.Checked Then
> Home.Details1.Append("Bottom side; ")
> End If
> If CheckBox19.Checked Then
> Home.Details1.Append("Insider / Inner; ")
> End If
> If CheckBox20.Checked Then
> Home.Details1.Append("Outside / Outer; ")
> End If
> If CheckBox21.Checked Then
> Home.Details1.Append("Above; ")
> End If
> If CheckBox22.Checked Then
> Home.Details1.Append("Below; ")
> End If
> If CheckBox23.Checked Then
> Home.Details1.Append("Lower; ")
> End If
> If CheckBox24.Checked Then
> Home.Details1.Append("Upper; ")
> End If
> If CheckBox27.Checked Then
> Home.Details1.Append("Bad installation; ")
> End If
> If CheckBox28.Checked Then
> Home.Details1.Append("Bent; ")
> End If
> If CheckBox29.Checked Then
> Home.Details1.Append("Damaged; ")
> End If
> If CheckBox30.Checked Then
> Home.Details1.Append("Dented; ")
> End If
> If CheckBox31.Checked Then
> Home.Details1.Append("Gap; ")
> End If
> If CheckBox32.Checked Then
> Home.Details1.Append("Incomplete; ")
> End If
> If CheckBox33.Checked Then
> Home.Details1.Append("Insufficient; ")
> End If
> If CheckBox34.Checked Then
> Home.Details1.Append("Loose; ")
> End If
> If CheckBox35.Checked Then
> Home.Details1.Append("Misaligned; ")
> End If
> If CheckBox36.Checked Then
> Home.Details1.Append("No access; ")
> End If
> If CheckBox37.Checked Then
> Home.Details1.Append("Uneven; ")
> End If
> If CheckBox38.Checked Then
> Home.Details1.Append("Not installed; ")
> End If
> If CheckBox39.Checked Then
> Home.Details1.Append("Not straight; ")
> End If
> If CheckBox40.Checked Then
> Home.Details1.Append("Rusted; ")
> End If
> If CheckBox41.Checked Then
> Home.Details1.Append("Sharp edges; ")
> End If
> If CheckBox42.Checked Then
> Home.Details1.Append("Too large; ")
> End If
> If CheckBox43.Checked Then
> Home.Details1.Append("Too long; ")
> End If
> If CheckBox44.Checked Then
> Home.Details1.Append("Too short; ")
> End If
> If CheckBox45.Checked Then
> Home.Details1.Append("Too Small; ")
> End If
> If CheckBox46.Checked Then
> Home.Details1.Append("Wrong type; ")
> End If
> If CheckBox47.Checked Then
> Home.Details1.Append("Wrong color; ")
> End If
> If CheckBox48.Checked Then
> Home.Details1.Append("Wrong size; ")
> End If
> If CheckBox25.Checked Then
> Home.Details1.Append("times 2; ")
> End If
> If CheckBox26.Checked Then
> Home.Details1.Append("times 3; ")
> End If
> If TextBox1.Text = "" Then
> 'do nothing
> Else
> Home.Details1.Append(", " & TextBox1.Text)
> End If
>
> Home.Details2 = Home.Details1.ToString
> Summary.Show()
> Me.Close()
>
> End If
> End Sub
>
>
>
> Private Sub Label16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
> About.Show()
> End Sub
>
>
> End Class
>
***** Exception Text ******* System.InvalidOperationException: Collection was modified; enumeration
operation may not execute. at
System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource
resource) at
System.Collections.Generic.List1.Enumerator.MoveNextRare() at
1.Enumerator.MoveNext() at
System.Collections.Generic.List
Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(Boolean
disposing) at
Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(Boolean
disposing) at System.ComponentModel.Component.Dispose() at
System.Windows.Forms.Control.Dispose(Boolean disposing) at
System.Windows.Forms.Form.Dispose(Boolean disposing) at
WindowsApplication1.PLocation.Dispose(Boolean disposing) at
System.ComponentModel.Component.Dispose() at
System.Windows.Forms.Form.WmClose(Message& m) at
System.Windows.Forms.Form.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个奇怪的问题。仅凭您发布的信息我无法确定可能是什么原因造成的。我也无法在这里重现该问题。看起来您的表单上确实有很多控件,这不一定是问题,但它可能有所贡献。
如果您愿意,请随时直接向我发送电子邮件 John.Hart @ Microsoft.com,我们会将其下线,看看是否可以查出真相。
谢谢,
约翰
This is a strange problem. I can't determine what might be causing it just from the information you've posted. I also wasn't able to reproduce the issue here either. It does look like you have a lot of controls on your form, not that would be the issue either necessarily but it may be contributing.
If you would like to, feel free to send me an email directly John.Hart @ Microsoft.com and we’ll take this off line to see if we can get to the bottom of it.
Thanks,
John