问题描述
我每隔1/2秒通过Threading.Timer轮询一个数据库,并在Windows窗体列表视图控件中显示结果。查询结果返回约150行,我首先将ADD添加到listview。填充列表视图后,我不再添加项目,我遍历列表视图的每一行并访问TEXT属性以更改每行的内容。我这样做所以我不必清除每个查询的listview,导致listview绘制并丢失它当前的滚动位置...
winForm是一个一点反应迟钝。我想如果我将控件的更新移动到主线程,表单会说响应,这会改善性能。
有人可以澄清一下是什么在这里,我需要做些什么来使表单更具响应性并提高使用新结果更新listview的效率,但不重新绘制listview并丢失它当前的滚动位置。
提前致谢,
-Dee
I'm polling a database every 1/2 second via Threading.Timer and displaying the results in a Windows Form listview control. The query results return about 150 rows that I initial 'ADD' to listview. Once the listview is populated I no longer 'ADD' items I iterate through each row of the listview and access the TEXT property to change the contents of each row. I do this so I won't have to clear the listview on each query causing the listview to paint and lose it's current scroll position...
The winForm is a little unresponsive. I thought if I moved the updating of the control off of the main thread that the form would say responsive and this would improve the performance.
Can someone please clarify what's going on here and what do I need to do to make the form more responsive and improve the efficiency of updating the listview with new result but without repainting the listview and losing it's current scroll position.
Thanks in advance,
-Dee
推荐答案
this.SuspendLayout();
this.listview.SuspendLayout();
//update control
//put listview manipulation code hrer to not cause refresh form
this.listview.ResumeLayout(false);
this.ResumeLayout(false);
这篇关于Threading.Timer与WinForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!