public CommentViewModelCollection(IBaconProvider baconProvider, string permaLink, string subreddit, string subredditId, string targetName) { _timerHandles = new List <WeakReference>(); _state = new Dictionary <object, object>(); _permaLink = permaLink; _subreddit = subreddit; _targetName = targetName; _baconProvider = baconProvider; var settingsService = baconProvider.GetService <ISettingsService>(); if (settingsService.IsOnline()) { _listingProvider = new BaconographyPortable.Model.Reddit.ListingHelpers.PostComments(baconProvider, subreddit, permaLink, targetName); } else { _listingProvider = new BaconographyPortable.Model.KitaroDB.ListingHelpers.PostComments(baconProvider, subredditId, permaLink, targetName); } //dont add to the observable collection all at once, make the view models on the background thread then start a ui timer to add them 10 at a time //to the actual observable collection leaving a bit of time in between so we dont block anything _systemServices = baconProvider.GetService <ISystemServices>(); _systemServices.RunAsync(RunInitialLoad); }
void RunUILoad(ref IEnumerable <ViewModelBase> remainingVMs, ObservableCollection <ViewModelBase> targetCollection, object timerHandle) { _systemServices.StopTimer(timerHandle); int vmCount = 0; int topLevelVMCount = 0; foreach (var vm in remainingVMs) { topLevelVMCount++; vmCount += CountVMChildren(vm); targetCollection.Add(vm); if (vmCount > 15) { break; } } if (vmCount >= 15) { remainingVMs = remainingVMs.Skip(topLevelVMCount); _systemServices.RunAsync(async(obj) => { _systemServices.RestartTimer(timerHandle); }); } }