gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:37:50 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com