嗨,我是 Silverlight/异步编程的新手
情况:Silverlight 应用程序作为进行 CRUD 操作的网络资源
问题:实体有一个插件步骤注册为同步。然后在 Silverlight 中,当代码执行 EndSaveChages(results) 方法时,我得到一个 SystemException。
收到的消息是:
当前对象并非源自异步结果。参数名称:asyncResult
我尝试使用锁、Thread.Sleep、While 和 Dispatcher,但没有任何帮助。有一种方法可以在我收到 asycResult 之前保留该过程?
代码:
private void OnUpdateRecordComplete (IAsyncResult result)
{
try
{
while (!result.IsCompleted)
{
}
Thread.Sleep(1000);
xrmsm_scores updatedRecord = result.AsyncState as xrmsm_scores;
context.EndSaveChanges(result);
// MessageBox.Show("Save Completed!");
MessageBox.Show(updatedRecord.xrmsm_studentsName.Trim() + "'s Grade has been updated!");
//MessageBox.Show("HUGE SUCCESS!");
}
catch (DataServiceRequestException se)
{
MessageBox.Show("The score information could not be saved.\nReason: " + getXMLError(se), "Error!", MessageBoxButton.OK);
studentName = string.Empty;
}
catch (SystemException se)
{
isSaved = true;
//string error = se.Message.Replace('"', '\'').Replace("\r\n", @"\n");
//MessageBox.Show("OnUpdateRecordComplete SystemExeption Catch: " + error);
//It always goes on catch because we are not using MVC System
//It saves it anyways :P
//MessageBox.Show("OnCreateRecordComplete");
//syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
}
}