App crashes when going back while an animation is still running

I have a series of awaits that happen to make views dance around and animate. The problem is, if while it's still running, you navigate away (and basically pop the top page where the animations are still playing), you get a crash. And it is sometimes made worse when you actually have a popModalAsync queued up after the animations, but the page was already popped by the user.

Any idea how I can add code to prevent this - I would ideally love to disable back in android and IOS, but as I understand that might be too complex, and the main goal I have is to simply let the app weasel out of the this problem elegantly.

public AnimatedNavBoardGrid()
{

grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
...
...
..
.
.
..
...
....
Content = grid;

 animateGrid();
}

 public async void animateGrid()
{
await grid.ScaleTo(1, 200);           
await Navigation.PopModalAsync();
}

Best Answer

Answers

  • PubuduGayanPubuduGayan NZMember ✭✭✭

    @PaulHoets

    after the Content = grid

    try like this

    Task.Run(async () => await animateGrid());

Sign In or Register to comment.