I want the data retrieval to load not in the ui thread, but in the background thread. I tried some examples from Google, but it still does not work.
ThreadPool.QueueUserWorkItem((o) => { IList<Asana> asanasRepo = null; var asanasRepository = this.GetService<IAsanasRepository>(); asanasRepo = asanasRepository.GetAllAsanas(); Asanas = asanasRepo.Select(x => new AsanasListItemViewModel { AsanaId = x.AsanaId, AsanaLevel = InfrastructureHelper.GetLevel(x.AsanaLevel), CoverImagePath = string.Format("/Content/Images/{0}", x.CoverImageFileName), UsualAsanaTitle = x.UsualTitle, YogaAsanaTitle = x.YogaTitle }).ToObservableCollection(); asanasDispatcher.BeginInvoke(() => { AsanasItems.Clear(); AsanasItems = (from asana in Asanas group asana by asana.AsanaLevel into c orderby c.Key select new Group<AsanasListItemViewModel>(c.Key, c) ).ToObservableCollection(); }); });
The main idea is to load data from the database, not into the ui stream, but in the background, when the data is downloaded, output it to ui. I tried something like the code above, but it does not work. can you help me with this? Thanks!
source share