如何在Windows商店应用的Deployment.Current.Dispatcher.BeginInvoke工作? [英] How the Deployment.Current.Dispatcher.BeginInvoke work in windows store app?

查看:201
本文介绍了如何在Windows商店应用的Deployment.Current.Dispatcher.BeginInvoke工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的Windows Phone 8的经验和我使用WCF数据服务,我能够用下面的代码成功更新我的记录:

i got experience with windows phone 8 and i am using WCF data services, i am able to update my record successfully with following code :

public void UpdateJob1(EquipBooking equipBooking)
        {
            this._context.UpdateObject(equipBooking);
            this._context.BeginSaveChanges(OnChangesSaved, this._context);
        }

        private void OnChangesSaved(IAsyncResult result)
        {
            bool errorFound = false;
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                this._context = result.AsyncState as THA001_devEntities;

                try
                {
                    // Complete the save changes operation.
                    this._context.EndSaveChanges(result);
                }
                catch (DataServiceRequestException ex)
                {
                    errorFound = true;
                    MessageBox.Show("Error, While Updating Record");
                }

                if (!errorFound)
                {
                    MessageBox.Show("Record Successfully Updated");
                }
            }
            );

        }



但我得到的问题,同时在窗口商店应用写相同的代码,我不能够更新记录,我有问题就在这里: Deployment.Current.Dispatcher.BeginInvoke

能任何人引导我,或重写我的代码?

can anyone guide me, or rewrite my code?

感谢

推荐答案

您是否尝试过使用,而不是Deployment.Current.Dispatcher.BeginInvoke这个

Have you tried using this instead of the Deployment.Current.Dispatcher.BeginInvoke

CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
      {

      });



编辑:

那么整个方法是:

private async void OnChangesSaved(IAsyncResult result)
{
    bool errorFound = false;
    CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
    await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
      {
        this._context = result.AsyncState as THA001_devEntities;
        try
        {
            // Complete the save changes operation.
            this._context.EndSaveChanges(result);
        }
        catch (DataServiceRequestException ex)
        {
            errorFound = true;
            MessageBox.Show("Error, While Updating Record");
        }

        if (!errorFound)
        {
            MessageBox.Show("Record Successfully Updated");
        }
      });
}

这篇关于如何在Windows商店应用的Deployment.Current.Dispatcher.BeginInvoke工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆