I have this method:
private async Task BackArrowTappedHandler() { Task<bool> sp = SavePageDataAsync(); await Task.WhenAll(sp); var saveResult = sp.Result; if (!saveResult) return; if (Device.RuntimePlatform is Device.iOS) await Navigation.PopModalAsync(); else await Shell.Current.Navigation.PopAsync(); } Which calls a method that I may or may not want to override:
public virtual async Task<bool> SavePageDataAsync() { return true; } Here is a short example of how I was doing the override just to make it more clear:
public async Task<bool> OnSavePageAsync() { var IsValueLess = false; if (daily < 20) { msg1 = "Minimum words"; msg2 = "Please set a number greater than 20"; IsValueLess = true; } var alertDeckPopup = new AlertPopup(msg2); await PopupNavigation.Instance.PushAsync(alertDeckPopup); if (IsValueLess) return false; else return true; } What I want to do is to check the result of SavePageDataAsync and based on the result, return or continue.
The only idea I have so far is to use Task.WhenAll
Can someone tell me if there is a better way that I can do this or if this is the only way then is it a valid way to do the check?
This code is giving me an error as I do not know how to correctly call SavePageData and then check the return value. Can someone give me advice on how I can do this?
awaitand therefore does not need to be markedasync. Omit async and returnTask.FromResult(true)instead, or better, mark it as abstract so that inheritors have to provide an implementation that actually does what it says on the tin