Hi! I've got a problem. When I trying to go to another page from Task.ContinueWith(() => { //And here i'm navigating } that's not works
Navigation works sometimes if I move navigation line from ContinueWith block, but in that case program behavior is unacceptable.
So, how to implement navigation after task completion?
Here is some codeasync void FromCameraButtonClicked (object sender, EventArgs e) { //Navigate to camera await AppLogic.TakePhotoFromCamera ().ContinueWith(async (t) => { if (t.Result == true) { var page = new EditPage(); this.Navigation.PushModalAsync(page); } }); //nav string here works }
Why are you mixing ContinueWith and await? You should only use one.
async void FromCameraButtonClicked (object sender, EventArgs e) { //Navigate to camera if (await AppLogic.TakePhotoFromCamera ()) { var page = new EditPage(); this.Navigation.PushModalAsync(page); } }
If that doesn't work then be more specific about what's going wrong.
Also, you can try to run the Navigation on MainThread like this:
Device.BeginInvokeOnMainThread (() => {
Navigation.PushAsync(page);
});
Might be because you're doing the work on a different thread.
Answers
Why are you mixing ContinueWith and await? You should only use one.
If that doesn't work then be more specific about what's going wrong.
Also, you can try to run the Navigation on MainThread like this:
Device.BeginInvokeOnMainThread (() => {
Navigation.PushAsync(page);
});
Might be because you're doing the work on a different thread.
adamkemp. thank you very mauch! Now works as it should.