Ejemplo n.º 1
0
        public void LoadRecommendations()
        {
            var context = TaskScheduler.FromCurrentSynchronizationContext();

            IsBusy = true;

            Recommendations.Clear();

            Task.Factory.StartNew(() =>
            {
                var users = dataLoader.LoadFollowings(settings.Username);
                var token = Task.Factory.CancellationToken;
                foreach (
                    var recommendation in
                    readLaterManager.GetReadLaterRecommendations().Select(
                        recommendationId =>
                        dataLoader.GetRecommendationById(recommendationId)))
                {
                    var current = recommendation;
                    Task.Factory.StartNew(() => Recommendations.Add(
                                              RecommendationViewModel.FromModel(
                                                  current,
                                                  users.Followings.Single(
                                                      c => c.Id == current.UserId),
                                                  settings.Font)), token,
                                          TaskCreationOptions.None, context);
                }
            }).ContinueWith(_ => IsBusy = false, context);
        }