Note that there are some explanatory texts on larger screens.

plurals
  1. POFill listbox with subitems async, makes listbox freeze
    text
    copied!<p>Im trying to fill a list box with a projectlist which contains a list of configurations.</p> <p>So what I'm trying to do is first fill the listbox with my projectlist and all subitems. This is all going well. But for each configuration I need to do a call to a rest service to get a status. So I do not whant to make all theese requests at once (first bind projects and configurations and then for each configuration fetch status and have the configuration status property updated async. But when I start to load all configurations (can be up to aprox 200) the listbox freezes.</p> <p><strong>RED: After some thinking it should be better to load status of each listitem (subitem) when it becoms visible for the user, however I can't find any good events for this. Any sugestions on how to handle this?</strong></p> <p>Here is my solution:</p> <pre><code>MainViewModel </code></pre> <pre class="lang-cs prettyprint-override"><code>//Fired on pageLoad _projectRepository.FindBy(_serverCityConfiguration, BuildListBoxGroups); private void BuildListBoxGroups(IEnumerable&lt;Project&gt; projects) { var projectGroups = new List&lt;ListBoxGroup&lt;BuildConfigurationModel&gt;&gt;(); foreach (Project project in projects) { var buildConfigurations = project.BuildConfigurations.Select(buildConfiguration =&gt; new BuildConfigurationModel(buildConfiguration.Id, buildConfiguration.Name, new List&lt;BuildModel&gt;())).ToList(); projectGroups.Add(new ListBoxGroup&lt;BuildConfigurationModel&gt;( new ProjectModel(project.Id, project.Name), buildConfigurations)); } Deployment.Current.Dispatcher.BeginInvoke(() =&gt; Projects = projectGroups.ToObservableCollection()); //It's here my problem starts, where my listbox freezes ThreadPool.QueueUserWorkItem(FireBuildsFetching, projects); } private void FireBuildsFetching(object stuff) { var projects = stuff as IEnumerable&lt;Project&gt;; foreach (var project in projects) { foreach (var buildConfiguration in project.BuildConfigurations) { ThreadPool.QueueUserWorkItem(RetrieveBuils, buildConfiguration); } } } private void RetrieveBuils(object buildConfiguration) { Debug.WriteLine("RetrieveBuils"); var localBuildConfig = buildConfiguration as BuildConfiguration; //Here is some logic to find correct buildconfiguration to add status to ... Deployment.Current.Dispatcher.BeginInvoke(() =&gt; buildConfigurationModel.AddBuilds(buildModels)); } </code></pre> <p>When all calls to rest service is done, the listbox is updated with all status at once.</p> <p>Someone having any good solutions to my problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload