两个构建操作“资源”之间有什么区别?和“嵌入式资源”在 Visual Studio 2010 中?
我已阅读以下文章,该文章应该解释它,但它对我没有帮助:
http://msdn.microsoft.com/en-us/library/ht9h2dk8(VS.80).aspx
我的情况是我想要一个包含数百个图标的 dll。并且图标dll将在各种应用程序中共享和使用。显然,如果一个应用程序只使用数十个图标,我不希望将所有这些图标加载到内存中。所以我很想知道“资源”(构建操作)是否允许我按需加载图标而不是一次加载全部图标。
有人可以帮忙吗?
I have read the following article which supposed to explain it, but it does not help me:
http://msdn.microsoft.com/en-us/library/ht9h2dk8(VS.80).aspx
My case is that I would like to have a dll which contains hundreds of icons. And the icons dll will be shared and used in various applications. Obviously, I would not like all those icons to be loaded in memory if one application just use tens of them. So I'm interested to know if "Resource" (the build action) would allow me to load icons on demand instead of loading all at once.
Could anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我目前还没有接近 Visual Studio,所以我无法直接测试它,但我会尝试帮助盲人。
对于初学者来说,如果您将所有资源放在一个 Zip 文件中,并作为内容加载到您的项目中,那么在您调用它们之前,应用程序不会加载它们。正如您提到的,如果您要放入大量文件,这是管理资源的好方法。
查看 Jeff Wilcox 的博客,了解 使用动态加载的 about页面了解更多信息。
您还可以查看 MSDN,其中详细介绍了使用 GetResourceStream 从 Zip 文件动态加载文件。
当然,根据您计划使用的文件数量,找到一种在编译时分割应用程序所需文件的方法可能是一个更好的选择。因为无论使用何种方法,将文件作为资源提取都会产生开销成本。
I'm no where near Visual Studio at the moment, so I can't test this out directly, but I'll attempt to help blind.
For starters, if you place all of your resources in a Zip file loaded added to your project as Content they won't be loaded by the application until you call them. This is a great way to manage resources if you're going to shove a large number of files in, as you mentioned.
Take a look at Jeff Wilcox' blog regarding using a dynamically loaded about page for more information.
You can also take a look at MSDN which details using GetResourceStream to load files from Zip files dynamically.
Of course, depending on how many files you plan on using it may be a far better option to find a way to segment out the files needed by the application at compile time. As there is an overhead cost to pulling a file in as a resource, irrespective of the method used.
构建操作“内容”可能是您真正要搜索的内容。在这种模式下,图标不会成为可执行文件的一部分,因此加载速度会更快。
“资源”和“嵌入式资源”的文档说:
因此,通过任何“资源”构建操作,它们都会被加载到内存中,而这并不是您想要的。
点击此处进行比较“内容”和“资源”操作。
Build action "Content" might be what you are really searching for. In this mode the icons won't be part of your executable which will thus load faster.
The documentation for "Resource" and "Embedded Resource" says:
So with any of the "Resource" build actions they will be loaded to memory what is not what you want.
Click here for a comparison of "Content" and "Resource" action.