Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put heavy init operations in MvvmCross

In an MvvmCross ViewModel, the Init method is used for any screen initialization. However, the screen is not drawn until Init is fully completed. I have some heavy operations (db searching). So ideally I would like to draw the screen with a progress bar, and then run my initialization methods, and finally update the screen. Where would I put these operations in the MvvmCross ViewModel?

like image 970
Ryan Langton Avatar asked Dec 16 '25 17:12

Ryan Langton


1 Answers

I would do heavy stuff in a Service. In that service i would either:

  • Make a method which triggers a Done event which you can listen for in your ViewModel and from there populate Properties with data.

or

  • Make an async method which you await on a background thread and when it returns you populate Properties.

While this service runs and fetches data, I would simply display something else on the screen, while the data loads. This could be some cached data or a progress bar or something else.

like image 93
Cheesebaron Avatar answered Dec 19 '25 09:12

Cheesebaron