小编Chr*_*ris的帖子

datagridview 上不稳定的 InvalidOperationException

我的 Winform 应用程序正在根AppDomain.CurrentDomain.UnhandledException级别记录和 Application.ThreadException ,我得到了这个异常:

System.InvalidOperationException:由于对象的当前状态,操作无效。在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e) 在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(对象发送者,ListChangedEventArgs e) 在 System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e) 在System.Windows.Forms.CurrencyManager.List_ListChanged(对象发送者,ListChangedEventArgs e)在System.ComponentModel.BindingList 1.OnListChanged(ListChangedEventArgs e) at System.ComponentModel.BindingList1.FireListChanged(ListChangedType类型,Int32索引)在System.ComponentModel.BindingList 1.InsertItem(Int32 index, T item) at System.Collections.ObjectModel.Collection1.Add(T项)在System.ComponentModel。 BindingList 1.AddNewCore() at System.ComponentModel.BindingList1.System.ComponentModel.IBindingList.AddNew() 在 System.Windows.Forms.CurrencyManager.AddNew() 在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew() 在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded ()在System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&dataGridViewCell,Int32 columnIndex,Int32 rowIndex,布尔canCreateNewRow,布尔validationFailureOccurred)在System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex,Int32 rowIndex,布尔setAnchorCellAddress,布尔validateCurrentCell ,布尔通过MouseClick)在System.Windows.Forms.DataGridView.ProcessDownKeyInternal(键keyData,布尔&移动)在System.Windows.Forms.DataGridView.ProcessEnterKey(键keyData)在System.Windows.Forms.DataGridView.ProcessDialogKey(键keyData)在System.Windows.Forms.Control.ProcessDialogKey(Keys keyData) 在 System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData) 在 System.Windows.Forms.Control.PreProcessMessage(Message& msg) 在 System.Windows.Forms.Control。 PreProcessControlMessageInternal(控制目标,消息&msg)在System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG&msg)

这是 ex.ToString() 的结果,它不返回我的应用程序的自定义代码,仅返回内部 System.Windows.Forms 方法。

在某些客户机器上有时会出现异常,我什至无法自己重现它。

这味道不好,我的假设是当我更改 datagridview 的数据源边界时。但在这种情况下,我至少应该在异常堆栈中看到我的类,但这里什么也没有。

有什么线索可以找到根本原因或进行调试吗?

非常感谢

c# .net-4.0 invalidoperationexception winforms

5
推荐指数
1
解决办法
1811
查看次数

C# 列表和内存

我是 C# 新手,想知道在 list1 = null; 之后 list1 是否真的从内存中删除。

List<string> list1 = new List<string>()
{
    "carrot",
    "fox",
    "explorer"
};
List<string> list2 = new List<string>();
list2.Add(list1[0]);
list2.Add(list1[1]);
list2.Add(list1[2]);

list1 = null;
Run Code Online (Sandbox Code Playgroud)

此代码仅用于文档,在我的实际情况中,list1 对象非常大,我需要将其从内存中删除,并仅继续使用 list2,它是原始 list1 的一小部分。

我假设 list1[0] 和 list2[0] 引用内存中的同一对象,直到我用新值更新 list2[0] ...这是正确的吗?

c# memory

3
推荐指数
1
解决办法
1万
查看次数