Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Deployment.Current.Dispatcher.BeginInvoke在windows应用商店应用程序中如何工作?_C#_Windows Phone 7_Windows Phone 8_Microsoft Metro_Windows Store Apps - Fatal编程技术网

C# Deployment.Current.Dispatcher.BeginInvoke在windows应用商店应用程序中如何工作?

C# Deployment.Current.Dispatcher.BeginInvoke在windows应用商店应用程序中如何工作?,c#,windows-phone-7,windows-phone-8,microsoft-metro,windows-store-apps,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);

我有使用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

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


谢谢

您是否尝试过使用此选项而不是部署。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");
        }
      });
}

这是我重新编写的,请批准语法

public void ModfityJobs(EquipBooking equipBooking)
        {
            try
            {
                this.IsDataLoaded = true;
                _context.BeginSaveChanges(ModfityJobsAsynchCallBack, equipBooking);
            }
            catch (Exception ex)
            {
            }
        }

        private void ModfityJobsAsynchCallBack(IAsyncResult synchresult)
        {
            try
            {
                dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                    {
                        _context.EndSaveChanges(synchresult);
                    });
            }
            catch (Exception)
            {

                throw;
            }
        }

我想,我不知道,你能重写我的代码吗?please@vb1在这里,方法被重写。我又添加了一个答案,如果它与您的答案相同,那么我会将您的答案标记为finalI get:System.invalidooperationexception:未找到可从中获取CoreDispatcher的当前窗口对象。或CoreWindow.GetForCurrentThread()仅为null。