Any ideas on updating CListCtrl icon in separate thread ?
-
I am having a virtual list control which can load a large number of file items. I have noticed that main speed issue here is file icon calculation, so I created the separate thread to calculate icon index in background. But, my problem is following: - how to communicate changes between the threads (I used to PostMessage for each calculated icon, but this was slowing down my icon thread enormously) - how to add icon calculations priority (if the user scrolls to the bottom of the list, those icons must be calculated first) I welcome any good idea or code pointer. Thanks in advance. Miroslav Rajcic
-
I am having a virtual list control which can load a large number of file items. I have noticed that main speed issue here is file icon calculation, so I created the separate thread to calculate icon index in background. But, my problem is following: - how to communicate changes between the threads (I used to PostMessage for each calculated icon, but this was slowing down my icon thread enormously) - how to add icon calculations priority (if the user scrolls to the bottom of the list, those icons must be calculated first) I welcome any good idea or code pointer. Thanks in advance. Miroslav Rajcic
PostMessage blocks the calling thread untill the window you sent the message processes it.. try SendMessage..
-
PostMessage blocks the calling thread untill the window you sent the message processes it.. try SendMessage..
I think the oposite is the truth :) Miroslav Rajcic
-
I am having a virtual list control which can load a large number of file items. I have noticed that main speed issue here is file icon calculation, so I created the separate thread to calculate icon index in background. But, my problem is following: - how to communicate changes between the threads (I used to PostMessage for each calculated icon, but this was slowing down my icon thread enormously) - how to add icon calculations priority (if the user scrolls to the bottom of the list, those icons must be calculated first) I welcome any good idea or code pointer. Thanks in advance. Miroslav Rajcic
You will probably need to "batch" the updates (e.g. load 10 icons, then update) anyway. Then, PostMessage is not an issue. You could call InvalidateRect from the worker thread, causing a new LVN_GETDISPINFO in the main thread (and they'd batch nicely). However, I see no chance to get the icon rect without stalling the main thread. You might use this for better prformance if the list is in Report Mode, though. (You need to invalidate the entire icon "column") I'm not sure if you need to set call SetImageList again after adding icons to it. Just try it, and don't if you don't need to. You probably need to keep a separate tracking file / icon, and track which icons are already loaded. in the LVN_GETDISPINFO handler, specify an empty / dummy icon id when it's not yet loaded. To prioritize: Share a variable iNextFileIndexToProcess, between the two threads, indicating the index in the list of the file who's icon is next to load. If an icon is already loaded, just skip to the next. If you arrive at the end of the list, start with the first one again. (You need a separate indicator that you have loaded all icons. e.g. break on iIconsLoaded == iFilesInList) Add a handler for WM_HSCROLL, where you set the iNextFileIndexToProcess to the first displayed item (LVM_GETTOPINDEX) This is just a rough outline, but I believe it's good ;)
Those who not hear the music think the dancers are mad. [sighist] [Agile Programming]
-
You will probably need to "batch" the updates (e.g. load 10 icons, then update) anyway. Then, PostMessage is not an issue. You could call InvalidateRect from the worker thread, causing a new LVN_GETDISPINFO in the main thread (and they'd batch nicely). However, I see no chance to get the icon rect without stalling the main thread. You might use this for better prformance if the list is in Report Mode, though. (You need to invalidate the entire icon "column") I'm not sure if you need to set call SetImageList again after adding icons to it. Just try it, and don't if you don't need to. You probably need to keep a separate tracking file / icon, and track which icons are already loaded. in the LVN_GETDISPINFO handler, specify an empty / dummy icon id when it's not yet loaded. To prioritize: Share a variable iNextFileIndexToProcess, between the two threads, indicating the index in the list of the file who's icon is next to load. If an icon is already loaded, just skip to the next. If you arrive at the end of the list, start with the first one again. (You need a separate indicator that you have loaded all icons. e.g. break on iIconsLoaded == iFilesInList) Add a handler for WM_HSCROLL, where you set the iNextFileIndexToProcess to the first displayed item (LVM_GETTOPINDEX) This is just a rough outline, but I believe it's good ;)
Those who not hear the music think the dancers are mad. [sighist] [Agile Programming]
Thank you for your effort. Your coments have been very valuable. I'll try them and see. Miroslav Rajcic
-
I think the oposite is the truth :) Miroslav Rajcic
Yes..Miroslav I checkd it and I was wrong.. thank you.. :)