c# - Demand load web based images on background thread? -
c# - Demand load web based images on background thread? -
i have application loads objects , displays them in grid. 1 of objects preview image either local image file or image file on web location. right working performance isn't when scrolling because whenever new item scrolls view has load preview takes sec or two.
what trying accomplish box preview show , start loading preview on background thread when scrolled view. when image loaded notify (via property alter event in view model) , image come place. way ui remains responsive , preview blank until loads , shows up. have getter bound property starting backgroundworker if image isn't cached, , worker routine follows (_previewcache backing property bound preview):
void bw_loadpreview_dowork(object sender, doworkeventargs e) { bitmapimage _tempcache = new bitmapimage(new uri(previewimagepath, urikind.relativeorabsolute)); if (_tempcache.canfreeze) { _tempcache.freeze(); dispatcher.currentdispatcher.invoke((action)(delegate { _previewcache = _tempcache; })); } }
this seems work pretty on local files, though takes little longer expect images appear, ui remains responsive. when image web path, ends _tempcache.canfreeze = false skips , doesn't load. if seek invoke without freezing, says can't utilize object because it's owned different thread.
what missing? how load web based image way? or there improve way approach issue i'm not seeing? help appreciated.
c# wpf multithreading image
Comments
Post a Comment