Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How do I do processing while a new screen is loading?

I have an app that loads a second screen that is pretty much just a Label and a Button (to return to the first screen). When the screen is called, I want it to load the screen (initially it has a "Working..." message), then do some lengthy calculation, then show the result. Putting everything in OnAppearing() doesn't work, as the screen doesn't appear until the calculation is done. I tried this:

protected override void OnAppearing()

    Task DoCalculation = new Task(() => { CalculateResult(); });

with CalculateResult() putting a value into the screen's Label's Text property, but the Label shows up as blank - and the second time I call the screen, the Button does not appear either.

How do I get the second screen's OnAppearing to load the screen, then complete a calcualtion and modify the display?

Best Answer


  • ThatDonGuyThatDonGuy Member ✭✭

    Thanks - that works...well, sort of. I can't get C# to recognize "async Task MyFunction()" as a valid function declaration (it throws "not all tasks return a value"), so I ended up using:
    await Task.Run(() => CalculateResult());
    instead of:
    await CalculateResult();

Sign In or Register to comment.