简体   繁体   中英

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

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.

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