.net - How to lazy load in C#? -


i'm developing emulator game. have object named "map", contains map's id, , other various information it. game contains lot of map objects (about 10,000). data located inside sql table, i'm using load it.

i have class named cachedmaps inherits keyedcollection of int , map. identifier map's id. unfortunately, takes 5 seconds load maps.

not maps visited, anyway. friend suggested use "lazy loading", i'm not sure how - like, load map's data or object when user enters it. how possible? thank you.

public class cachedmaps : keyedcollection<int, map> {     public cachedmaps()         : base()     {         // loading code.         // this.add(new map(....));     } } 

you should use lazy generic class purpose that.

use example msdn : (the "large object" map):

lazylargeobject = new lazy<largeobject>(() =>  {     largeobject large = new largeobject(thread.currentthread.managedthreadid);     // perform additional initialization here.      return large; }); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -