Deployment.Current.Dispatcher.BeginInvoke如何在Windowsapp store中运行?
我有使用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如何在Windowsapp store中运行?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
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; } }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/985698.html