New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using the Initialize event in a view model since upgrade to Version 6.0 #2808

Closed
JimWilcox3 opened this Issue Apr 17, 2018 · 8 comments

Comments

Projects
None yet
3 participants
@JimWilcox3
Contributor

JimWilcox3 commented Apr 17, 2018

https://github.com/JimWilcox3/MvvmCrossInitializeTest

Steps to reproduce 馃摐

  1. The project will hang up if you run it as is. The View is never displayed.

  2. If you comment out the ColorList = await SomeData.GetColors(); in the Initialize, the View is displayed but the colors are not loaded.

  3. If you un-comment the Task in the constructor, the colors will load and the View will be displayed.

Expected behavior 馃

You should be able to use an async Task to load data in the Initialize of the View Model.

Actual behavior 馃悰

It makes the call to load the data then hangs and never shows the View.

Configuration 馃敡

Version: 6.0

Platform:

  • 馃摫 iOS
  • 馃 Android
  • 馃弫 WPF
  • 馃寧 UWP
  • 馃崕 MacOS
  • 馃摵 tvOS
  • 馃悞 Xamarin.Forms
@martijn00

This comment has been minimized.

Member

martijn00 commented Apr 18, 2018

What if you use .ConfigureAwait(false);?

@JimWilcox3

This comment has been minimized.

Contributor

JimWilcox3 commented Apr 18, 2018

Where exactly would I use this? I do want to await the calls in Initialize. I was thinking this was the whole purpose of having an async Initialize to do the heavy loading. It worked fine under version 5.x. I can use a workaround if that's what it will take.

@martijn00

This comment has been minimized.

Member

martijn00 commented Apr 18, 2018

A good read on this is: https://medium.com/bynder-tech/c-why-you-should-use-configureawait-false-in-your-library-code-d7837dce3d7f

It's not a workaround, it's what you are supposed to do.

@JimWilcox3

This comment has been minimized.

Contributor

JimWilcox3 commented Apr 18, 2018

It is puzzling that this app has been working for years and now it has to be configured differently and only in the Initialize of a ViewModel. I had to add the ConfigureAwait(false) in the Initialize and in the call to the data service, but it started working.

If you don't mind me asking, what is it about the Initialize event that makes you have to do this now?

@nickrandolph

This comment has been minimized.

Contributor

nickrandolph commented Apr 18, 2018

I think this is only true of the first view model. The first navigation is forced to be done synchronously.
If you鈥檙e using the splashscreen you can do some initialisation logic before navigating to the first view model which would allow you to complete the losing of that data asynchronously.

@JimWilcox3

This comment has been minimized.

Contributor

JimWilcox3 commented Apr 18, 2018

@nickrandolph it seems you are correct that it is only on the first View Model. After that, the other View Models work as expected. I am using a SplashScreen. Can you tell me what sort of initialization logic I could do to make the first View Model Initialization be asynchronous?

@nickrandolph

This comment has been minimized.

Contributor

nickrandolph commented Apr 18, 2018

@JimWilcox3 check out my post https://nicksnettravels.builttoroam.com/post/2018/04/19/MvvmCross-Initialize-method-on-the-first-view-model.aspx
I'm going to close this issue as there are work arounds and this change was by design

@JimWilcox3

This comment has been minimized.

Contributor

JimWilcox3 commented Apr 19, 2018

@nickrandolph Thanks for posting that. It was helpful and informative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment