1

I'm working on a business application (C#, WPF, EF, MVVM). I need to load a bunch of items from database, create view models for them and put them in a window. Is there a way to create the view model in another thread or do something similar to speed up UI?

  1. The approximate average time needed to fetch all items from database = 1s
  2. The approximate average time needed to instantiate all view models = 3s

I'm doing the first part through Loaded event of each item. but the second part is the bottleneck. any insight would be appreciated.

Larry Smithmier
5301 gold badge3 silver badges9 bronze badges
asked Jan 8, 2014 at 13:54
5
  • Creating view models in a background thread is generally a bad idea since they need to be bound on controls created on the main thread. I would try to reduce the initialization time first. Commented Jan 8, 2014 at 15:15
  • Or employ some layered caching. Commented Jan 8, 2014 at 21:07
  • @Dtex: Thanks, I can remove some unnecessary graphics. Commented Jan 8, 2014 at 21:37
  • @Robert: can you explain how layer caching can be done? Commented Jan 8, 2014 at 21:37
  • 1
    msdn.microsoft.com/en-us/library/dd997362(v=vs.110).aspx Commented Jan 8, 2014 at 22:16

1 Answer 1

1

Break up the views into separate tabs/fly-outs etc and only populate these bits when the tabs/fly-outs are actually switched to.

Further to the above only populate the first element i.e. SELECT 1 only then populate the rest in the view on a scroll or drop down operation etc..

Lazy Loading.

In other words this is some of the layered caching alluded too and i do not see why the ViewModel has to have the data in advance as long as it goes off and gets it whenever requested..

answered Sep 27, 2016 at 7:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.