【发布时间】:2012-06-24 16:20:47
【问题描述】:
我有一些数据,我在一项任务中对其进行了更新:该应用程序目前对于一个想法来说是一个黑客,因此对代码表示歉意。
Task.Factory.StartNew(() =>
{
dataGridView1.BeginInvoke((Action)(() =>
{
dataGridView1.SuspendLayout();
}));
dataSet1.Reset();
da.Fill(dataSet1);
dataGridView1.BeginInvoke((Action)(() =>
{
dataGridView1.DataSource = dataSet1.Tables[0];
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].Width = 50;
dataGridView1.ResumeLayout();
}));
}
).ContinueWith(task =>
{
if (dataSet1.Tables[0].Rows.Count > 0)
{
if (lastcount != dataSet1.Tables[0].Rows.Count)
{
lastcount = dataSet1.Tables[0].Rows.Count;
if (lastcount == 0)
{
NotifyWithMessage("The items have been cleared", "Items cleared");
}
else
{
NotifyWithMessage(String.Format("There are {0} new items in your monitor", dataSet1.Tables[0].Rows.Count));
}
}
}
}
);
现在,代码基本上可以工作了。没有错误,这很好..
当它在任务之外更新时,datavgridview 根本没有闪烁,当我在调试中运行它时,它非常小,并且在黑客可以接受的范围内......当我在调试之外运行它时......这非常明显!暂停和恢复布局根本没有任何区别。我需要线程中的代码,因为 UI 在没有响应的情况下是块状的 - 虽然它是可以接受的,但它现在的刷新很糟糕。
我的 Datagridview 是根据单元格颜色自定义颜色的,但是,我只是不明白为什么调试和发布之间存在差异,我希望性能反过来!
(我试过 Invoke 和 BeginInvoke...)
我看了看Horrible redraw performance of the DataGridView on one of my two screens
而且在debug下,这个一点也不闪烁,一点点都没有……在release条件下,有一个可笑的闪烁……
我能做什么?
【问题讨论】:
标签: c# datagridview