C# System.InvalidOperationException:集合已修改;枚举操作可能无法执行
我研究过这个问题,但还没有找到适合我的问题。我不想编辑我正在循环浏览的内容。
************** Exception Text **************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
这是导致它的函数:
internal static bool CloseAllForms()
{
try
{
if (clsGlobal.g_objfrmCustomerInformation != null)
clsGlobal.g_objfrmCustomerInformation.Close();
if (clsGlobal.g_objfrmSearchCustomer != null)
clsGlobal.g_objfrmSearchCustomer.Close();
if (clsGlobal.g_objfrmSwipeLicense != null)
clsGlobal.g_objfrmSwipeLicense.Close();
if (clsGlobal.g_objfrmSearchResults != null)
clsGlobal.g_objfrmSearchResults.Close();
if (clsGlobal.g_objfrmCustomerData != null)
clsGlobal.g_objfrmCustomerData.Close();
if (clsGlobal.g_objfrmPurchaseOrder != null)
clsGlobal.g_objfrmPurchaseOrder.Close();
if (clsGlobal.g_objfrmAddPurchaseOrderItem != null)
clsGlobal.g_objfrmAddPurchaseOrderItem.Close();
if ((clsGlobal.g_objfrmCustomerInformation == null) && (clsGlobal.g_objfrmSearchCustomer == null) && (clsGlobal.g_objfrmSwipeLicense == null) && (clsGlobal.g_objfrmSearchResults == null) && (clsGlobal.g_objfrmCustomerData == null) && (clsGlobal.g_objfrmPurchaseOrder == null) && (clsGlobal.g_objfrmAddPurchaseOrderItem == null))
{
PrepareImageBar();
return true;
}
else
{
PrepareImageBar();
return false;
}
}
catch (Exception ex)
{
string ErrorMessage;
ErrorMessage = "Error: " + ex.Message +
"\r\nSource: " + ex.Source +
"\r\nTargetSite: " + ex.TargetSite.ToString() +
"\r\nStackTrace: " + ex.StackTrace.ToString();
if (ex.Data.Count > 0)
{
ErrorMessage += "\r\nData Count: " + ex.Data.Count.ToString() +
"\r\nKeys: " + ex.Data.Keys.ToString() +
"\r\nValues: " + ex.Data.Values.ToString();
}
MessageBox.Show(ErrorMessage, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
CustomFunctions.emailExceptionToAuthor(ex);
return false;
}
}
这就是我调用该函数的方式:
if (CloseAllForms())
{
if (clsGlobal.g_objfrmPurchaseOrder == null)
{
clsGlobal.g_objfrmPurchaseOrder = new frmPurchaseOrder();
clsGlobal.g_objfrmPurchaseOrder.FormClosed += PurchaseOrderFormClosed;
clsGlobal.g_objfrmPurchaseOrder.MdiParent = clsGlobal.g_objfrmMDIMain;
clsGlobal.g_objfrmPurchaseOrder.Show();
clsGlobal.g_objfrmPurchaseOrder.BringToFront();
}
else
{
clsGlobal.g_objfrmPurchaseOrder.Show();
clsGlobal.g_objfrmPurchaseOrder.BringToFront();
}
PrepareImageBar();
}
请帮助我!
更新:这是完整的代码。
例外情况 有关调用的详细信息,请参阅此消息的末尾 即时 (JIT) 调试而不是此对话框。
************** Exception Text **************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at 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 B2HD_Software.frmCustomerData.Dispose(Boolean disposing)
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)
准备ImageBar();
internal static void PrepareImageBar()
{
clsGlobal.g_objfrmMDIMain.mnuImageBarAddCustomer.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddCustomer.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarFindCustomer.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarFindCustomer.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Enabled = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarNewPurchase.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarNewPurchase.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddItem.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddItem.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarModifyItem.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarModifyItem.Enabled = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarDeleteItem.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarDeleteItem.Enabled = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSavePicture.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSavePicture.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarAdmin.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarAdmin.Enabled = true;
switch (clsGlobal.ActiveForm())
{
case "CustomerInformation":
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Enabled = true;
break;
case "SearchCustomer":
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Enabled = false;
break;
case "SwipeLicense":
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
break;
case "CustomerData":
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarNewPurchase.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Visible = true;
break;
case "PurchaseOrder":
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddItem.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarDeleteItem.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarModifyItem.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = true;
clsGlobal.g_objfrmPurchaseOrder.ShowProperButtons();
break;
case "AddPurchaseOrderItem":
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = true;
break;
default:
clsGlobal.g_objfrmMDIMain.mnuImageBarAddCustomer.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarFindCustomer.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Visible = true;
break;
}
}
CloseAllForms()
internal static bool CloseAllForms()
{
if (clsGlobal.g_objfrmCustomerInformation != null)
clsGlobal.g_objfrmCustomerInformation.Close();
if (clsGlobal.g_objfrmSearchCustomer != null)
clsGlobal.g_objfrmSearchCustomer.Close();
if (clsGlobal.g_objfrmSwipeLicense != null)
clsGlobal.g_objfrmSwipeLicense.Close();
if (clsGlobal.g_objfrmSearchResults != null)
clsGlobal.g_objfrmSearchResults.Close();
if (clsGlobal.g_objfrmCustomerData != null)
clsGlobal.g_objfrmCustomerData.Close();
if (clsGlobal.g_objfrmPurchaseOrder != null)
clsGlobal.g_objfrmPurchaseOrder.Close();
if (clsGlobal.g_objfrmAddPurchaseOrderItem != null)
clsGlobal.g_objfrmAddPurchaseOrderItem.Close();
if ((clsGlobal.g_objfrmCustomerInformation == null) && (clsGlobal.g_objfrmSearchCustomer == null) && (clsGlobal.g_objfrmSwipeLicense == null) && (clsGlobal.g_objfrmSearchResults == null) && (clsGlobal.g_objfrmCustomerData == null) && (clsGlobal.g_objfrmPurchaseOrder == null) && (clsGlobal.g_objfrmAddPurchaseOrderItem == null))
{
PrepareImageBar();
return true;
}
else
{
PrepareImageBar();
return false;
}
}
这是我的关闭事件在每个表单上的样子。
internal static void CustomerInformationFormClosed(object sender, FormClosedEventArgs e)
{
clsGlobal.g_objfrmCustomerInformation = null;
PrepareImageBar();
}
I have researched this issue and haven't found what pertains to me yet. I am not trying to edit something I am looping through.
************** Exception Text **************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
Here is my function that is causing it:
internal static bool CloseAllForms()
{
try
{
if (clsGlobal.g_objfrmCustomerInformation != null)
clsGlobal.g_objfrmCustomerInformation.Close();
if (clsGlobal.g_objfrmSearchCustomer != null)
clsGlobal.g_objfrmSearchCustomer.Close();
if (clsGlobal.g_objfrmSwipeLicense != null)
clsGlobal.g_objfrmSwipeLicense.Close();
if (clsGlobal.g_objfrmSearchResults != null)
clsGlobal.g_objfrmSearchResults.Close();
if (clsGlobal.g_objfrmCustomerData != null)
clsGlobal.g_objfrmCustomerData.Close();
if (clsGlobal.g_objfrmPurchaseOrder != null)
clsGlobal.g_objfrmPurchaseOrder.Close();
if (clsGlobal.g_objfrmAddPurchaseOrderItem != null)
clsGlobal.g_objfrmAddPurchaseOrderItem.Close();
if ((clsGlobal.g_objfrmCustomerInformation == null) && (clsGlobal.g_objfrmSearchCustomer == null) && (clsGlobal.g_objfrmSwipeLicense == null) && (clsGlobal.g_objfrmSearchResults == null) && (clsGlobal.g_objfrmCustomerData == null) && (clsGlobal.g_objfrmPurchaseOrder == null) && (clsGlobal.g_objfrmAddPurchaseOrderItem == null))
{
PrepareImageBar();
return true;
}
else
{
PrepareImageBar();
return false;
}
}
catch (Exception ex)
{
string ErrorMessage;
ErrorMessage = "Error: " + ex.Message +
"\r\nSource: " + ex.Source +
"\r\nTargetSite: " + ex.TargetSite.ToString() +
"\r\nStackTrace: " + ex.StackTrace.ToString();
if (ex.Data.Count > 0)
{
ErrorMessage += "\r\nData Count: " + ex.Data.Count.ToString() +
"\r\nKeys: " + ex.Data.Keys.ToString() +
"\r\nValues: " + ex.Data.Values.ToString();
}
MessageBox.Show(ErrorMessage, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
CustomFunctions.emailExceptionToAuthor(ex);
return false;
}
}
This is how I call the function:
if (CloseAllForms())
{
if (clsGlobal.g_objfrmPurchaseOrder == null)
{
clsGlobal.g_objfrmPurchaseOrder = new frmPurchaseOrder();
clsGlobal.g_objfrmPurchaseOrder.FormClosed += PurchaseOrderFormClosed;
clsGlobal.g_objfrmPurchaseOrder.MdiParent = clsGlobal.g_objfrmMDIMain;
clsGlobal.g_objfrmPurchaseOrder.Show();
clsGlobal.g_objfrmPurchaseOrder.BringToFront();
}
else
{
clsGlobal.g_objfrmPurchaseOrder.Show();
clsGlobal.g_objfrmPurchaseOrder.BringToFront();
}
PrepareImageBar();
}
Please help me!
UPDATE: Here is the full code.
The exception
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at 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 B2HD_Software.frmCustomerData.Dispose(Boolean disposing)
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)
PrepareImageBar();
internal static void PrepareImageBar()
{
clsGlobal.g_objfrmMDIMain.mnuImageBarAddCustomer.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddCustomer.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarFindCustomer.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarFindCustomer.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Enabled = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarNewPurchase.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarNewPurchase.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddItem.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddItem.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarModifyItem.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarModifyItem.Enabled = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarDeleteItem.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarDeleteItem.Enabled = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSavePicture.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSavePicture.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Enabled = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarAdmin.Visible = false;
clsGlobal.g_objfrmMDIMain.mnuImageBarAdmin.Enabled = true;
switch (clsGlobal.ActiveForm())
{
case "CustomerInformation":
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Enabled = true;
break;
case "SearchCustomer":
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarStartSearch.Enabled = false;
break;
case "SwipeLicense":
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
break;
case "CustomerData":
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarNewPurchase.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Visible = true;
break;
case "PurchaseOrder":
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarAddItem.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarDeleteItem.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarModifyItem.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarEditCustomer.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = true;
clsGlobal.g_objfrmPurchaseOrder.ShowProperButtons();
break;
case "AddPurchaseOrderItem":
clsGlobal.g_objfrmMDIMain.mnuImageBarTakePicture.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSave.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarCancel.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarViewNotes.Visible = true;
break;
default:
clsGlobal.g_objfrmMDIMain.mnuImageBarAddCustomer.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarFindCustomer.Visible = true;
clsGlobal.g_objfrmMDIMain.mnuImageBarSwipeLicense.Visible = true;
break;
}
}
CloseAllForms()
internal static bool CloseAllForms()
{
if (clsGlobal.g_objfrmCustomerInformation != null)
clsGlobal.g_objfrmCustomerInformation.Close();
if (clsGlobal.g_objfrmSearchCustomer != null)
clsGlobal.g_objfrmSearchCustomer.Close();
if (clsGlobal.g_objfrmSwipeLicense != null)
clsGlobal.g_objfrmSwipeLicense.Close();
if (clsGlobal.g_objfrmSearchResults != null)
clsGlobal.g_objfrmSearchResults.Close();
if (clsGlobal.g_objfrmCustomerData != null)
clsGlobal.g_objfrmCustomerData.Close();
if (clsGlobal.g_objfrmPurchaseOrder != null)
clsGlobal.g_objfrmPurchaseOrder.Close();
if (clsGlobal.g_objfrmAddPurchaseOrderItem != null)
clsGlobal.g_objfrmAddPurchaseOrderItem.Close();
if ((clsGlobal.g_objfrmCustomerInformation == null) && (clsGlobal.g_objfrmSearchCustomer == null) && (clsGlobal.g_objfrmSwipeLicense == null) && (clsGlobal.g_objfrmSearchResults == null) && (clsGlobal.g_objfrmCustomerData == null) && (clsGlobal.g_objfrmPurchaseOrder == null) && (clsGlobal.g_objfrmAddPurchaseOrderItem == null))
{
PrepareImageBar();
return true;
}
else
{
PrepareImageBar();
return false;
}
}
This is what my close event looks like on each form.
internal static void CustomerInformationFormClosed(object sender, FormClosedEventArgs e)
{
clsGlobal.g_objfrmCustomerInformation = null;
PrepareImageBar();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看到三种可能性:
FormClosed
事件处理程序出现故障(即,可能PurchaseOrderFormClosed
中出现故障)。CloseAllForms()
方法在catch
中执行大量工作。代码可能在那里失败。发生错误时,您是否看到MessageBox
?电子邮件发送了吗?尝试注释掉那里的所有代码,看看是否仍然出现错误。或者可能只是暂时用MessageBox.Show(ex.ToString())
替换catch
中的所有代码,这样您就可以确定您所看到的异常正在发生在尝试
中。PrepareImageBar()
出现问题。尝试注释掉该方法,看看是否仍然出现错误。I see three possibilities:
FormClosed
event handler for one of the forms (i.e., maybe something inPurchaseOrderFormClosed
).CloseAllForms()
method is doing a bunch of work in thecatch
. It could be possible that the code is failing there. When the error occurs, do you see theMessageBox
? Does the email get sent? Try commenting out all of the code there and see if you still get the error. Or maybe just temporarily replace all of the code in thecatch
with aMessageBox.Show(ex.ToString())
so you can be sure the exception you are seeing is occurring in thetry
.PrepareImageBar()
. Try commenting out that method and see if you still get the error.我不知道异常发生在哪里,但异常可能是在修改集合的
foreach
代码块中生成的。这里,修改意味着“添加”或“删除”,类似于:枚举时不能修改集合。
更新
要查找代码中发生的位置,在调试时,您可以检查“异常”对话框中的“用户未处理选项”(Ctrl+Alt+E)。但是,请注意,要使用此选项,VS 必须在“调试”选项中设置“仅启用我的代码”。
I don't know where the exception was occurred but the exception might be generated in
foreach
code block where the collection was modified. Here, the modification means 'Add' or 'Remove' something like:A collection cannot be modified while enumerating.
UPDATED
To find where it was occurred if being in your code, while debugging, you would check the 'user unhandled option' in Exceptions dialog (Ctrl+Alt+E). However, please note that to use this option, VS has to be set 'Enable just My Code' in Debugging option.
我见过这个错误:
该错误显然只出现在某些 Windows 安装上,而且我从未通过调试在开发环境中出现过该错误,只有完整的应用程序。
这是 VisualBasic.PowerPacks 中的一个错误。
请参阅此处获取解决方案< /a> (参见博客末尾)。
您基本上必须重写表单 Dispose() 方法并手动处理所有 VisualBasic Powerpack 项目。
I've seen this bug:
The error apparently only shows up on some windows installs, and I've never gotten it to occur in the development environment via debug, only the full app.
This is a bug in the VisualBasic.PowerPacks.
See here for a solution (see the end of the blog).
You basically have to override the forms Dispose() method and manually dispose of all VisualBasic Powerpack items.