1
我想弄清楚,鉴于下面的代码,刷新()需要发生在UI线程?它似乎工作,我想知道如果CollectionViewSource实际上是一个线程感知/安全的对象?它肯定有属性和方法来支持调用正确的线程,只是不确定是否由开发人员决定,还是在对象内完成?Silverlight的CollectionViewSource是线程安全的吗?
public CollectionViewSource UserList { get; private set; }
void setupCollections()
{
UserList = new CollectionViewSource();
UserList.Source = searchProvider.UserResults;
UserList.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending));
}
此线程在Silverlight中是否安全?
void RefreshUserList()
{
UserList.View.Refresh();
}
或者您是否需要这样做?
void RefreshUserList()
{
// Is This Required?
UserList.Dispatcher.BeginInvoke(() =>
{
UserList.View.Refresh();
});
// Or MVVM-light Method
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
UserList.View.Refresh();
});
}