【求助】this.Invoke()报错问题
private int[] delIndex = null;//待删行号的数组
private bool delFlag = true;//是否要不间断尝试删除数组中的行
private bool deling = false;//是否有线程正在执行删除操作的锁变量
private void PushDelIndex(int _index)
{
if (delIndex == null)
{
delIndex = new int[] { _index };
}
else
{
Array.Resize(ref delIndex, delIndex.Length + 1);//展示如何扩充数组
delIndex[delIndex.Length - 1] = _index;
}
}
void delRowThread()
{
delFlag = true;
while (delFlag)
{
if (delIndex != null)
{
if (deling == false)
{
delRow();
}
}
Thread.Sleep(100);
}
}
private delegate void delRowCallBack();
void delRow()
{
if (this.InvokeRequired)
{
deling = true;
delRowCallBack o = new delRowCallBack(delRow);
this.Invoke(o);
}
else
{
for (int i = 0; i < delIndex.Length; i++)
{
dataGridView.Rows.RemoveAt(delIndex[i]);
}
delFlag = false;
deling = false;
delIndex = null;
}
}
private void DataGridView_RowLeave(object sender, DataGridViewCellEventArgs e)
{
DataGridView dataGridView = (DataGridView)sender;
bool isNullRow = true;
for (int columnIndex = 0; columnIndex < dataGridView.Columns.Count-1; columnIndex++)
{
isNullRow = isNullRow && (dataGridView.CurrentRow.Cells[columnIndex].Value == null);
}
if (isNullRow)
{
PushDelIndex(dataGridView.CurrentRow.Index);
Thread delTh = new Thread(new ThreadStart(delRowThread));
delTh.Start();
}
}
问题是:当DataGridView没失去焦点时,程序运行正常,但当DataGridView失去焦点时,程序运行到this.Invoke(o)时报错。
相关推荐
Vue 解决通过this.$refs来获取DOM或者组件报错问题
主要介绍了Vue 解决通过this.$refs来获取DOM或者组件报错问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
InvocationHandler中invoke()方法的调用问题分析
主要介绍了InvocationHandler中invoke()方法的调用问题分析,具有一定参考价值,需要的朋友可以了解下。
Vue中的this.$options.data()和this.$data用法说明
问题 项目里遇到一个问题,用this.$options.data()重置组件data时,data()里用this获取的props或method都为undefined,代码简化如下: export default { props: { P: Object }, data () { return { A: { a: this.methodA }, B: this.P }; }, methods: { resetData () { // 更新时调用 Object.assign(thi
解决vue this.$forceUpdate() 处理页面刷新问题(v-for循环值刷新等)
主要介绍了解决vue this.$forceUpdate() 处理页面刷新问题(v-for循环值刷新等),解决方法是使用this.$forceUpdate()强制刷新,文章给大家分享了代码案例,需要的朋友参考下吧
Canvas引入跨域的图片导致toDataURL()报错的问题的解决
主要介绍了Canvas引入跨域的图片导致toDataURL()报错的问题的解决的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧



