在循环中进行多个异步调用
我正在 SilverLight 4 RIA 应用程序中加载(通过拖放)多个文档。当我队列中只有一条记录(即 _uploadedDocuments.Count =1)时,AddNewXDocument 异步调用(在下面的代码中)效果很好。但是,如果我删除多个文件,则在第一个文件的 Submit 事件完成之前调用第二个 AddNewXDocument 方法。我收到“SubmitChanges 操作已在此 DomainContext 上进行”错误。
如何使用 IAsyncResult 延迟调用文件 2 的 AddNewXDocument 方法,直到文件 1 的 Submit 事件完成之后。我还可以在循环中加入一个视觉指示器来通知用户加载过程正在进行中吗?
foreach (var updDoc in _uploadedDocuments)
{
string docTitle = GetUniqueFileName(updDoc.Title.Replace(updDoc.FileExtension, ""), updDoc.FileExtension.ToLower());
var doc = new XDocument();
doc.Description = docTitle;
_myViewModel.AddNewXDocument(doc);
}
I am loading (via drag and drop) multiple documents in a SilverLight 4 RIA application. The AddNewXDocument asyn call (in the code below) works great when i have just one record in the queue- i.e. _uploadedDocuments.Count =1. If I drop multiple files, however, the second AddNewXDocument method is called before the Submit event for the first file completes. I get the "A SubmitChanges operation is already in progress on this DomainContext" error.
How can I use IAsyncResult to delay calling the AddNewXDocument method for file 2 till after the Submit event for file 1 completes. Can I also tie in a visual indicator in the loop to inform user that a Load process is in progress ??
foreach (var updDoc in _uploadedDocuments)
{
string docTitle = GetUniqueFileName(updDoc.Title.Replace(updDoc.FileExtension, ""), updDoc.FileExtension.ToLower());
var doc = new XDocument();
doc.Description = docTitle;
_myViewModel.AddNewXDocument(doc);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论