wpf - Parallel.ForEach hangs the layout in MVVM while working on big Lists -
i have generic list contains 1100 elements. 10 of these elements contain 1000 elements each (of same type). elements bound ui datagrid. itrating list takes long time 5-6 seconds (because properties manipulate in iterations databound datagrid properties).
here iteration code:
parallel.foreach(this.allparameters, par => { foreach (parameter subpar in par.wrappedsubparameters) { subpar.isselected = false; } par.isselected = false; });
the code snippet in xaml looks like:
<datagrid.rowstyle> <style targettype="{x:type datagridrow}" basedon="{staticresource {x:type datagridrow}}"> <setter property="isselected" value="{binding isselected, mode=oneway}" />
as in previous question suggested use parallel iteration, hangs ui , never returns back. how can suspend ui before doing iterations in mvvm. doing code in right way? please suggesst. thanks
you can find answer here: link thing is, cant call parallel.foreach on ui thread. if not sure current thread, can use method this:
public static bool checkisrunningonuithread() { if (application.current == null) return false; var dispatcher = application.current.dispatcher; if (dispatcher==null) return false; return dispatcher.checkaccess(); }
Comments
Post a Comment