【发布时间】:2011-07-15 21:32:33
【问题描述】:
我正在使用带有 Silverlight 的 RIA 服务,并使用以下代码在 DataItemCollection 中加载集合。
我的问题是 LoadOperation 运行它返回 0 行,然后在一段时间后,它再次获得调试器中的控制权,然后运行 for 循环,然后给出正确的计数。
因此,它似乎是异步的。如何同步获取它,以便在返回数据时给我正确的计数?
ReportingCategoryContentAssociationContext _ReportingCategoryContentAssociationContext = new ReportingCategoryContentAssociationContext();
DataItemCollection lstdt = new DataItemCollection();
LoadOperation loadopt = _ReportingCategoryContentAssociationContext.Load(_ReportingCategoryContentAssociationContext.GetReportingContentScoreByCategoryQuery());
loadopt.Completed += (s, args) =>
{
if (!loadopt.HasError)
{
DataItem dtitem = null;
foreach (GetReportingCategoriesContentScore_Result Lkt in ((LoadOperation<GetReportingCategoriesContentScore_Result>)s).Entities)
{
dtitem = new DataItem();
dtitem.ReportingCategoryID = Lkt.CategoryID;
dtitem.ParentCategoryID = Lkt.ParentCategoryID;
dtitem.CategoryTitle = Lkt.CategoryTitle;
lstdt.Add(dtitem);
}
}
};
【问题讨论】:
-
HiTech Magic 的回答是正确的。由于它是异步的,您是否遇到任何问题?
标签: silverlight wcf-ria-services synchronous