C# 在一个漫长的过程中产生使用
假设我有一个函数C# 在一个漫长的过程中产生使用,c#,wpf,C#,Wpf,假设我有一个函数 public IList<type> Fetch() { IList<type> list = new List<type>(); //here comes a really long process and an item gets added to the list every few seconds return list; } 上面的函数必须等待Fetch()函数返回一个值,但我希望在添加项
public IList<type> Fetch()
{
IList<type> list = new List<type>();
//here comes a really long process and an item gets added to the list every few seconds
return list;
}
上面的函数必须等待Fetch()函数返回一个值,但我希望在添加项时更新视图,因此我认为应该向该函数发送对databound属性的引用,例如,它看起来像:
Fetch(AnObjectThatHasADataboundProperty.ThatProperty);
- 你会这样做吗
- 我以前从未使用过
,这种情况下应该使用yield吗 被使用yield
如果然后从某个地方更新集合,视图也会自动更新。哪个GUI是WPF或WinForm使用ObservableCollection并绑定到它。@poke如果这样做,我仍然必须发送ObservableCollection属性作为对Fetch函数的引用,然后添加到它?@poke我不知道已经有这样一个类可用,谢谢。
Fetch(AnObjectThatHasADataboundProperty.ThatProperty);