Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Resource Manager vs Resource File C#

Posted on 2011-03-19
4
Medium Priority
?
743 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 31

Accepted Solution

by:
MlandaT earned 2000 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 31

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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