开发者

DataGridView blocks the UI Thread

I am working on application which uses a DataGridView control. Since there is a lot of data I use the VirtualMode to use paging, but even with this feature this take a while to update DataGridView. So I created a control which spins and entertain an user. Unfortunately there are some issues with this solution, namely when the entertainment control spins the UI Thread does handle any of requests from it because it's so busy with this DataGridVi开发者_C百科ew.

What should I do to access the UI Thread even if it is so busy? How do you do to "entertain" an user when you use the DataGridView or is there any main to prevent UI Thread from blocking by DataGridView?

btw. I know that Application.DoEvents probably could help, but I prefer not to use it.


Drop the priority of the DataGridView thread relative to the UI one or just throw in the occasional Thread.Sleep in the DGV data load function.

Combined with a little tuning of your page sizes that should sort it.


I'm not sure what your implementation looks like, so forgive me if you already know this: Setting the VirtualMode property to "true" doesn't make the DataGridView automatically populate itself via just-in-time loading. Rather, it just gives you as the developer the ability to do so. If you're using virtual mode but still populating the entire thing at once, then you really aren't gaining anything. Instead you'll have to implement your own paging algorithm. This is actually pretty easy to do. Please take a look at this MSDN topic for an example. Hopefully that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜