Xamarin IMobileServiceTable同步运行

时间:2015-06-08 16:54:33

标签: c# xamarin azure-mobile-services

使用IMobileServiceTable接口,如何同步调用方法的结果。例如。下面的GetTask方法:

public class ItemsManager {

    IMobileServiceTable<Item> itemTable;
    private ItemViewModel _itemViewModel = new ItemViewModel ();


    public ItemsManager()
    {
        this.itemTable = App.client.GetTable<Item>();
        App.SetItemsManager(this);
    }


    //This seems to just hang
    public Item GetTask(string id, string barcode)
    {

            var qry =  itemTable.Where(a => a.ItemID == id || a.BarCodeID == id);
            return qry.Query.FirstOrDefault();

    }
}

我正在尝试通过扫描方法获取结果,并将项目记录提取到另一种形式:

async void OnProductScanClicked (object sender, EventArgs e)
    {
        var result = await BarCodes.Instance.Read ();
        if (!result.Success) {
            await this.DisplayAlert ("Scan Failed", "Failed to get barcode", "OK");
        } else {
            var msg = String.Format ("Barcode : {0} - {1}", result.Format, result.Code);
            App.SetItemsManager(new ItemsManager());
            var item = App.ItemManager.GetTask(result.Code, result.Format.ToString());

            if (item == null) {
                await this.DisplayAlert ("Item Not Found!", msg, "OK");
            }
            else {
                var myPage = new ItemsXaml();
                myPage.BindingContext = item;
                await Navigation.PushModalAsync (myPage);
            }

        }

    }

1 个答案:

答案 0 :(得分:0)

我对这些东西不熟悉,现在已经弄清楚如何做到这一点。我们只需要在调用任何异步函数时添加 await 方法。