c# - Only loading and unloading data based on what's visible in a VirtualObjectListView, using ObjectListView? -
i'm writing video manager in c# using objectlistview, preview images generated, saved, , entry put sqlite db. there, use virtualobjectlistview component display entries (including first image preview) in details mode.
the problem i've ran several hundred+ entries, starts eat ram , i'm seeing a lot of files (lots of duplicates too) open/locked in process explorer. so, i've attempted implement caching system - 30 images loaded @ time, , ones not needed unloaded while new ones loaded.
it doesn't work. ends loading multiple copies of each file somehow, , feels... hacky. i've spent past few days looking event or can bind method to, - can't, i've had use getnthobject in abstractvirtuallistdatasource.
anyways, here's code:
public override object getnthobject(int n) { videoinfo p = (videoinfo)this.objects[n % this.objects.count]; p.id = n; int storebufferhalf = 5; int storefrom = (n - storebufferhalf < 0) ? 0 : n - storebufferhalf; int storeto = (n + storebufferhalf >= objects.count()) ? objects.count() - 1 : n + storebufferhalf; foreach (int cacheitem in cachelist.tolist()) { if (cacheitem >= storefrom && cacheitem <= storeto) continue; videoinfo unloaditem = (videoinfo)this.objects[cacheitem]; //debug.writeline(cacheitem + " preparing delete cache: " + unloaditem.name); unloaditem.destroypreviewimage(); cachelist.remove(cacheitem); } //load items cache. (int = storefrom; < storeto; i++) { if (!cachelist.contains(i)) { videoinfo loaditem = (videoinfo)this.objects[i]; if (loaditem.previewimage != null) continue; loaditem.setpreviewimage(); cachelist.add(i); } } return p; }
some more information: basically, kind of works... does load multiple copies of each file, end loading more images should after scroll down bit (the entire test db of 60 items, actually), scrolling list , down few times gets unload files (at least according process explorer).
after that, starts loading them again, of them multiple times...
i think need group/split input source list.
consider using this answer means split ienumerable n parts. use button next/last section, , set binding source.
Comments
Post a Comment