Solved

Resource Manager vs Resource File C#

Posted on 2011-03-19
4
727 Views
Last Modified: 2012-05-11
I have a resource setup with a bunch of 16x16 PNG's that we use for images on a tree view.

We build this treeviews in code and we used to use an imagelist which gaves us trouble so we were adding the images like this:

treeNode.LeftImages.Add(gloabl::project.rsx16.phoneImage);

Now, on a large set of data (7K records, 3 nodes deep so that is 21K nodes) we would randomly get out of memory errors. Even on a dev machine with 8gig ram. So, I did a little digging and found the resourcemanager class in System.Resources, and tried this;

ResourceManager rm = new ResourceManager(resourceFile, etc);
treeNode.LeftImages.Add((Image)rm.GetObject("phoneImage");

I decided before I go further, let me ask, which way is right? Or should I before the loop that  populates the tree create an instance of the image? I want to enusre that ONE instance of the image exists, but also want to follow best practices.

Image phone = (Image)rm.GetObject etc;

treeNode.LefImages.Add(phone);
0
Comment
Question by:melegant99
  • 2
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
MlandaT earned 500 total points
ID: 35386816
I generally find that working with the ImageList is a faster option for working with a large treeview. How about loading the resource images into the ImageList at runtime first? Then just configuring the treeview to use the imageList as normal.

21,000 nodes in a treeview also sounds like overkill... from teh perspective of usability. Does the user really need to have all 21,000 nodes loaded in one go into the tree? How about only adding the child nodes when the user expands a node (might be less responsive than preloading the child nodes, especially where there are many child nodes at the same level, but this results in less runtime memory usage... and even a lower startup time for the tree in the first place since it wont be loading 21,000 nodes)?
0
 

Author Comment

by:melegant99
ID: 35410968
Hi,
If I use an imagelist, does that mean all the nodes will point to one instance of the image in memory, or am I getting an image for every node?

Yes, the 21K is overkill. However it is 21K in a multiple of levels, at the root maybe there are 100 nodes.

Thanks for responding btw, this question sat out there a long time.
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 35414599
ImageList yes. From what I understand, it uses handles and pointers internally so you wont have a copy of the image for each item.

21,000... yes... even if you put it in multiple levels. If you think of it from a usability point of view, it's really a lot for a tree...  I think :) ... I doubt any of your users will ever really need to go through all those items at any one time :)
0
 

Author Closing Comment

by:melegant99
ID: 35414762
Going to change to the tree to be more on demand.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now