简体   繁体   中英

callback function in async await in xamarin forms

I am trying to have a callback function in xamarin forms to alert the user that the task is finished. I haven't figured it out yet and am not sure what is wrong. Any help is appreciated with the proper way of doing this.

The code below is in a button click event. The method FinishPurchase never gets called.

Task<bool> task = StockDataController.Instance.WasItemPurchased(CloudInfo.IAPMonthlySubscriptionProductID);
Task continuation = task.ContinueWith(t=>FinishPurchase());
continuation.Wait();

Previously I was calling the code below in the button click event but I want to execute specific code after the method WasItemPurchased is executed,etc.

bool result=await StockDataController.Instance.WasItemPurchased(CloudInfo.IAPMonthlySubscriptionProductID)

The if statement, below, will be called once WasItemPurchased completes.

bool isResultSuccessful = await StockDataController.Instance.WasItemPurchased(CloudInfo.IAPMonthlySubscriptionProductID);

if (isResultSuccessful)
{
    //Do Something
}
else
{
    //Do Something else
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM