i developing windows app. there model class property coversource of type imagesource , property filename of type string. both of them data bidden views can't make getters or setters async functions. want in setter of filename, async function called , after coversource set asynchronously reading file applicationdata.current.localfolder. newbie c# , little google. how write such async function , call callback, in javascript?
you have couple of conflicting requirements here. first, windows platform (just other modern mobile platform) requires view updates synchronous. blocking ui thread not considered acceptable; updates must immediate. secondly, reading file i/o-based operation, , naturally asynchronous. forces non-blocking approach.
the answer realize both requirements correct. ui must updated immediately, , file i/o must take arbitrary amount of time. so, proper design think ui looks while i/o in progress, , purposefully design scenario.
something should work:
public string filename { { return filename; } set { filename = value; loadfileasync(); } } private async task loadfileasync() { try { coversource = ...; // "loading" image or something. var image = await ...; coversource = image; } catch (exception ex) { coversource = ...; // "error" image or something. } } i have msdn article on async data binding goes more detail, , introduces notifytaskcompletion type takes care of lot of boilerplate code approach.
Comments
Post a Comment