开发者

How can I get file icons on Windows asynchronously (and ideally in parallel) from C++?

开发者 https://www.devze.com 2023-02-02 16:26 出处:网络
The MSDN documentation for SHGetFileInfo says, quite rightly: You should call this function from a background thread. Failure to do so could cause the UI to stop responding.

The MSDN documentation for SHGetFileInfo says, quite rightly:

You should call this function from a background thread. Failure to do so could cause the UI to stop responding.

so I'm trying to figure out a good way to do this where I have a large list开发者_开发技巧 (80+) of them to do, and would like to parallelize the underlying I/O. I could use a thread-pool, but I'm not an expert Windows programmer, so I was wondering if there was a better technique for this.


Create a queue of file names to process (a linked list would suffice; consider STL's std::list). Create a lock for that queue (a critical section would do). Spawn a bunch of threads (2-4). Each thread would acquire the lock, get the head from the queue, release the lock and retrieve the icon - in the loop. If no more items in the queue, the thread quits. Something like this.


Making parallel I/O calls might not give you any speed up (likely only an overhead). You can experiment with GBL library and see if threading helps you. Write handler functions to respond to events. Then you can easily switch between AsyncHandler, which uses thread pool and Handler, which is synchronous to see if you can achieve any speedup.

0

精彩评论

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

关注公众号