在循环中进行多个异步调用

发布于 2024-12-16 13:55:24 字数 730 浏览 2 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文