//定义委托省略//开始线程
ThreadGetIteams = new Thread(new ThreadStart(this.isInvoke));
ThreadGetIteams.Start();//判断UI
private void isInvoke()
{
if (!dataGridView1.InvokeRequired)//如果在UI主线程操作dataGridView1,
{
dataGridView1.Refresh();//则直接进行控件操作,“与UI主线程相关联”
}
else//如果是在另一线程操作dataGridView1,则启用委托
{
dataGridView1.Invoke(new deleRefreshDataGridView(getIteams));
}
}
private void getIteams()
{
//得到Iteams集合,约万余条记录略
//定义容器
List<string[]> IteamsList = new List<string[]>(); while (Iteams总数)
{
IteamsList .Add(Iteams集合.GetValue(2).ToString().Split('_'));
} //后面省略
}
单步调试跟踪了一下,运行到while循环处最花时间,且UI主线程会无响应,卡几秒钟。
如何才能不卡?如果放个进度条的话,进度条的操作放在哪里?
解决方案 »
- C# Winform 关于AutoUpdate的更新问题
- 老师说创建一个人民币类..可是怎么包括元角分的数据呢?
- 多线程 web程序的 效率问题 为什么和单线程差不多, 5 分种的一个过程 只比单线程 快30秒?
- 为什么说c#中的委托是"类型安全"的?
- 动态生成表格的问题,请教大虾们。。
- 求 asp.net从数据库中取数据绘制曲线图 的代码! 谢谢前辈了
- 急!C#如何引用excel的数据透视表功能,高手给的提示!
- VC#是否可以自动添加控件事件?每次手工写对象事件真是麻烦~~~
- C#鼠标拖动效果
- 有关数据库->dateset->XML->dateset->数据库的问题
- 怎么在C#的环境下,自动改变y轴的刻度。
- 一个文本截取的问题
{
var datas=进行计算得到所有结果数据(); //这里需要花90%的时间
dataGridView1.Invoke(new deleRefreshDataGridView(getIteams), datas); //datas作为getIteams的参数
}
引用楼主 sgbaobao 的回复:
if (!dataGridView1.InvokeRequired)//如果在UI主线程操作dataGridView1,
{
dataGridView1.Refresh();//则直接进行控件操作,“与UI主线程相关联”
}
else//如果是在另一线程操作dataGridView1,则启用委托
{
dataGridView1.Invoke(ne……
呵呵,大虾真风趣
我的线程里没有做大量操作控件的事情,只是刷新了一个dataGridView。即使不用这样的判断,直接调用dataGridView1.Invoke(new deleRefreshDataGridView(getIteams));
也会在while地方卡一会。
这一句相当于把线程又交回去了?