c# - Deployment.Current.Dispatcher.BeginInvoke 如何在 Windows 应用商店应用程序中工作?

标签 c# windows-phone-7 windows-phone-8 microsoft-metro windows-store-apps

我有使用 Windows Phone 8 的经验并且我正在使用 WCF 数据服务,我能够使用以下代码成功更新我的记录:

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

谁能指导我,或者重写我的代码?

谢谢

最佳答案

你试过用这个代替 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");
        }
      });
}

关于c# - Deployment.Current.Dispatcher.BeginInvoke 如何在 Windows 应用商店应用程序中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20443805/

相关文章:

silverlight - Windows Phone 7的开发平台是什么

windows-phone-7 - Windows Phone 7 内置声音

windows-phone-8 - WP8 中 GZIPSTREAM 的替代品

javascript - 从代码隐藏 asp.net 调用 Javascript

c# - '[未知 ]' property does not point to a DependencyObject in path ' (0).(1)[3].(2)'

windows - Windows 8 开发/Metro 风格应用程序所需的工具?

c# - Windows Phone 类库中的 RecourceDictionary

c# - SpecialFolder.个人位置

c# - 是否有带谓词的 String.IndexOf?

c# - Distinct() 不调用 equals 方法