我用线程读取本地xml中的数据并在datagridview中展示,数据量大的时候界面会卡。主要代码如下:
private void PreDelegateLoad()
{
WaitCallback preDelegateWaitCallback = new WaitCallback(PreDelegate);
ThreadPool.QueueUserWorkItem(preDelegateWaitCallback, null);
}
public void PreDelegate(object obj)
{
PreDeletageCallback preDelegateCallback = new PreDeletageCallback(dgPreDelegateLoad);
Invoke(preDelegateCallback);
}
private void dgPreDelegateLoad()
{
//读取本地xml,设置datagriadeview的数据源
dgPreDelegateRefresh();
for (int i = 0; i < dgPreDelegate.Columns.Count; i++)
{
ColItemInfo colItemInfo = (ColItemInfo)preOrderItemInfo.m_htItemInfo[dgPreDelegate.Columns[i].Name];
if (colItemInfo == null) continue;
dgPreDelegate.Columns[i].HeaderText = colItemInfo.name;
dgPreDelegate.Columns[i].MinimumWidth = colItemInfo.width;
dgPreDelegate.Columns[i].FillWeight = colItemInfo.width;
dgPreDelegate.Columns[i].DefaultCellStyle.Format = colItemInfo.format;
if (colItemInfo.sortID == 1)
{
dgPreDelegate.Columns[i].SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
}
else
{
dgPreDelegate.Columns[i].SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
}
if (!preOrderItemInfo.m_strItems.Contains(dgPreDelegate.Columns[i].Name)) dgPreDelegate.Columns[i].Visible = false;
if (i == 0) dgPreDelegate.Columns[i].ReadOnly = false;
else dgPreDelegate.Columns[i].ReadOnly = true;
}
}
那位大侠能告诉我为什么会卡吗? |