multithreading - WPF Two Way Binding and Updating UI from Background Thread -


i fear may know answer question i'm holding out smallest glimmer of hope wrong.

i have repository contains collection property list of items. collection updated webservice call 1 of 2 things. if first call create new instance of item each row returned, populate it, , add collection. subsequent calls instead item in collection , update properties. viewmodel, item class, , repository implement inotifypropertychanged.

the call dataservice executes every 30 seconds updating data using async / await task similar this: how execute method periodically wpf client application using threading or timer. viewmodel takes items repositorys collection , splits them various collection properties. view binds via itemscontrol individual items in each collection , properties continually updated.

it works beautifully... but, dataservice call isn't in own thread , despite async/await ui gets little unresponsive every 30 seconds. when went put dataservice call in backgroundworker realized can't when threw exception modifying different thread.

i familar issue winforms hoping somehow sidestep wpf , twoway binding. there way make ui more responsive async/await or there way put updates in thread without having write events support dispatcher updates on main thread?

use "binding.isasync" property in binding. set isasync property true when accessor of binding source property might take long time. when isasync property true ui not blocked until value bound. more info : msdn

one example image property accessor downloads web. setting isasync true avoids blocking ui while download occurs.

also can use prioritybinding achieve requirement. prioritybinding in windows presentation foundation (wpf) works specifying list of bindings. list of bindings ordered highest priority lowest priority. if highest priority binding returns value when processed there never need process other bindings in list. case highest priority binding takes long time evaluated, next highest priority returns value used until binding of higher priority returns value successfully.

<prioritybinding fallbackvalue="defaultvalue">         <binding path="slowestdp" isasync="true"/>         <binding path="slowerdp" isasync="true"/>         <binding path="fastdp" /> </prioritybinding> 

detailed info : prioritybinding


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -