Results 1 to 7 of 7

Thread: [RESOLVED] Dispose large number of controls quickly? or better manage resources?

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Dispose large number of controls quickly? or better manage resources?

    jmcilhinney, Thank you for taking the time to write out that example. I just got home and I'll be doing some testing with it soon. Do I not have to directly .dispose each item? Does the "Me.garbage.TryDequeue(ctrl)" actually release the resources? I'm sure I'll see something while testing, but since the error is something that only happens every couple thousand instances, it may be a bit harder to know exactly what's going on (from the perspective of someone who only just recently learned of that method)

    Shaggy Hiker, I understand where you're coming from. I was originally drawing the images myself and working from there, but I've implemented other parts of the interface where I depend on having unique controls that I can assign other properties to. I'm using the Tag property quite a bit, and unique contex menus. I'm also assigning them unique tooltips at generation. I know that can be done in a custom control, but it adds to the complexity, when I'm not trying to reinvent the wheel. In regards to only displaying so many controls at once, from a UI standpoint, there are generally about 50 images visible at one time (but they are dynamically sizable, so there could be many more at any one time, depending on user settings), I currently have approximately 680 items loading in each load, but there are times where many fewer are loaded at once. Part of the reason it operates this way is that its *kind of* like a file browser, where it loads anything it finds in the directories, and displays them. I would rather not index, or keep a database, because I'm constantly changing the locations of the files, and creating other files along side them, I don't want to run the risk of it losing sync and losing track of files. It may be a bit less efficient this way, but its not like I'm working on hundreds of thousands of files for a large company. This is a small tool which may be used for a couple thousand files total, and currently it only takes about 2 seconds to load nearly 700 files, that's more than efficient enough for its purpose.

    Another thing to consider is that I'm not loading large files, I'm actually dynamically generating and saving thumbnails the exact size of the preview images (if there isn't already a thumbnail available), so its not like I'm loading 700+ 2MB files, I'm only loading about 10-100kb files.

    I do appreciate the input though, looking at different ways to solve similar problems are always great at opening up creativity.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Dispose large number of controls quickly? or better manage resources?

    Quote Originally Posted by stepdragon View Post
    jmcilhinney, Thank you for taking the time to write out that example. I just got home and I'll be doing some testing with it soon. Do I not have to directly .dispose each item? Does the "Me.garbage.TryDequeue(ctrl)" actually release the resources? I'm sure I'll see something while testing, but since the error is something that only happens every couple thousand instances, it may be a bit harder to know exactly what's going on (from the perspective of someone who only just recently learned of that method)
    Yes, you do have to dispose each control. That's why each control is being disposed in the ProgressChanged event handler. As is the point of the BackgroundWorker, DoWork is raised on a secondary thread and ProgressChanged is raised on the UI thread. That's why manipulating the queue can be done in the DoWork event handler while manipulating the controls, i.e. disposing them, must be done in the ProgressChanged event handler.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width