Search code examples
c#graphicsresourcescompact-frameworkembedded-resource

C# Better way of managing UI graphics


I'm building a UI framework for a mobile application and I have a question about managing UI graphics.

Right now I'm storing all the graphics as embedded resources. But the GUI part of the project is seperated into 3 different Projects and NameSpaces, each containing graphics as embedded resources. One of the Projects is a base type and doesn't know about the other two, and the other two Projects need resources from their NameSpace and Assembly and from the third (base) Namespace and Assembly

What I have been doing is when a resource is requested via the file name, I go through each of the three project's Assembly object's list of GetManifestResourceNames, sort them, then search for the first string that contains the file name. I'm noticing that for each graphic it is taking 11-14 ms just to get this string! When all is said and done, I'm looking at 60-100 ms just in resource name lookup

I know there must be a better way to dynamically find a resource across projects and namespaces using only the file name. Any help with this would be excellent!

Also, having the resources be embedded isn't a constraint. If there is a better solution that doesn't involve ER, that'd be great!


Solution

  • 60-100ms isn't bad as a one-off operation, so you could create your own cache class which gets this out of the way early on during app execution - it could use a Dictionary object so you get very fast lookup times from that point on.

    If you don't have the list in advance, you could fall back on a 'lazy-loaded' cache, i.e. the value is looked up the first time it's requested, then stored for future accesses.

    Hope that helps.