简体   繁体   中英

Multithreaded GridView hangs when refreshing itself

I have a multithreaded app which uses a thread to constantly update a datatable, a gridview is bound to this table in the windows form. Background thread updates the datatable and sometimes calls gridview beginInvoke() method so gridview can reflect some of the updates in real time. Everything looks fine and there is no error. However when I try to do any kind of UI change to the gridview (clicking on cells, scrolling, sorting, even resizing or minimize maximizing main form) it hangs and I cannot even see what's the error. If anyone is familiar with that gridview does when its refreshing it UI and how can i fix this, I would really appreciate to share with me. MY first guess to overcome this problem is duplicating another datatable and updating it constantly and binding gridview to this one, I only say this because when I unbind gridview from datatable, everything works great. Thanks for your help.

Background threads should NEVER update the UI. The fact that they do, is probably due to bad design. I would go like this:

Background threads throw events that contain any new data to the UI. UI does what ever it needs to show the new data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM