如何从C ++异步(理想情况下并行)在Windows上获取文件图标? [英] How can I get file icons on Windows asynchronously (and ideally in parallel) from C++?

查看:75
本文介绍了如何从C ++异步(理想情况下并行)在Windows上获取文件图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SHGetFileInfo的MSDN文档说得很对:

您应该从后台线程调用此函数.否则可能会导致UI停止响应.

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

所以我试图找出一种很好的方法来执行此操作,因为我要处理的列表很大(超过80个),并且希望并行化基础I/O.我可以使用线程池,但是我不是Windows专家,所以我想知道是否有更好的技术.

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.

推荐答案

创建要处理的文件名队列(链接列表就足够了;考虑STL的std :: list).为该队列创建一个锁(关键部分可以这样做).产生一堆线程(2-4).每个线程都会获取锁,从队列中获取头部,释放锁并检索图标(在循环中).如果队列中没有更多项目,则线程退出.像这样的东西.

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.

这篇关于如何从C ++异步(理想情况下并行)在Windows上获取文件图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆