winform程序,每次需要从数据库中读取10万多条数据,不能分页。因为读取数据库等待时间较长,我用了begininvoke等方法不占用界面线程,同时提示一个滚动条。但是我在给datagridview的datasource赋值的时候(datagridview.datasource=dt),界面就会进入假死状态,等大概10秒钟后绑定完成才能显示出来。我觉得可能是在绑定的时候占用了界面线程,但是我这个方法明明是写在begininvoke里面的,不知道该怎么解决。附代码,各位帮帮忙,多谢啦!
//创建委托
delegate void GetDateDelegate();
delegate void BindGrid();
//定义全局datatable
DataTable dt;
private void button1_Click(object sender, EventArgs e)
{
//执行方法
GetDateDelegate getdate = new GetDateDelegate(GetDate); getdate.BeginInvoke(null, null);
}
/// <summary>
/// 取得数据
/// </summary>
void GetDate()
{
dt = BLL.Common.GetAttr();//从数据库获得10万条以上的datatable
FillData();
} /// <summary>
/// 绑定datagrid
/// </summary>
private void FillData()
{ if (dataGridView1.InvokeRequired)
{
BindGrid filldate = new BindGrid(FillData);
this.BeginInvoke(filldate);
}
else
{
this.dataGridView1.DataSource = dt;
} }
//创建委托
delegate void GetDateDelegate();
delegate void BindGrid();
//定义全局datatable
DataTable dt;
private void button1_Click(object sender, EventArgs e)
{
//执行方法
GetDateDelegate getdate = new GetDateDelegate(GetDate); getdate.BeginInvoke(null, null);
}
/// <summary>
/// 取得数据
/// </summary>
void GetDate()
{
dt = BLL.Common.GetAttr();//从数据库获得10万条以上的datatable
FillData();
} /// <summary>
/// 绑定datagrid
/// </summary>
private void FillData()
{ if (dataGridView1.InvokeRequired)
{
BindGrid filldate = new BindGrid(FillData);
this.BeginInvoke(filldate);
}
else
{
this.dataGridView1.DataSource = dt;
} }
private void button1_Click(object sender, EventArgs e)
{
Thread mythread = new Thread(new ThreadStart(NewThread));
mythread.Start();
}
private void NewThread()
{
//取得数据
dt = BLL.Common.GetAttr();
dataGridView1.BeginInvoke(new BindGrid(ThreadFillDate));
}
private void ThreadFillDate()
{
//就在这一步会出现白屏
dataGridView1.DataSource = dt;
}Datagridview在绑定的时候我明明没有用界面线程啊,为什么还会出现白屏呢?
只绑定主键和排序的列