我对此完全陌生,但试图学习。我确信有一个简单的答案,但我不知道谷歌正确的问题。我敢肯定这一定是个常见问题。
在使用WCF服务的MVVM模式上使用Visual Studio 2010,WPF,.net 4.0时,我完全可以使用它:
private void RefreshEncountertimes()
{
// consume the WCF service.
this.dataservice.GetEncounterDetailsCompleted += (s, e) =>
{
this.Encounterdetails = e.Result;
};
// call the WCF service
this.dataservice.GetEncounterDetailsAsync(Calendardate);
}
其中Encounterdetails是:
private IEnumerable<EncounterDetail> encounterdetails;
public IEnumerable<EncounterDetail> Encounterdetails
{
get
{
return this.encounterdetails;
}
set
{
this.encounterdetails = value;
this.OnPropertyChanged("Encounterdetails");
}
}
然而,当试图计算返回的Encounterdetails如下:
// search for encounters of the calendardate
private void RefreshEncountertimes()
{
// consume the WCF service.
this.dataservice.GetEncounterDetailsCompleted += (s, e) =>
{
this.Encounterdetails = e.Result;
this.ListCount = Encounterdetails.Count(); //<---CRASHES WITH INFINITIE LOOP
};
// call the WCF service
this.dataservice.GetEncounterDetailsAsync(Calendardate);
}
其中ListCount为:
private int listcount;
public int ListCount
{
get
{
return listcount;
}
set
{
this.listcount = value;
OnPropertyChanged("ListCount");
CanFindPatient = ListCount > 0;
}
}
它崩溃了: 无法计算表达式,因为当前线程处于堆栈溢出状态。
那么如何从异步过程中获取返回的IEnumerable的计数?
任何帮助都将不胜感激。