Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是Silverlight';s CollectionViewSource线程安全?_Silverlight_Thread Safety_Mvvm Light_Collectionviewsource - Fatal编程技术网

是Silverlight';s CollectionViewSource线程安全?

是Silverlight';s CollectionViewSource线程安全?,silverlight,thread-safety,mvvm-light,collectionviewsource,Silverlight,Thread Safety,Mvvm Light,Collectionviewsource,我试图弄清楚,给定以下代码,是否需要在UI线程上执行Refresh()?它似乎起作用了,我想知道CollectionViewSource是否实际上是一个线程感知/安全的对象?它肯定有支持调用正确线程的属性和方法,只是不确定这是留给开发人员的,还是在对象中完成的 public CollectionViewSource UserList { get; private set; } void setupCollections() { UserList = new Col

我试图弄清楚,给定以下代码,是否需要在UI线程上执行Refresh()?它似乎起作用了,我想知道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();
            });
    }

根据Microsoft的文档,CollectionViewSource对象不是线程安全的。这似乎不是线程安全的,尽管它在很多情况下似乎都能工作

这可能是因为调用的方法实际上在视图上,而不是CollectionViewSource。该视图返回一个接口-支持类的详细信息未知,只是CreateView()方法创建了该接口

我建议我们总是认为这不是线程安全的,并将其发送到正确的线程中,尽管我对VIEW .Rebug()的测试至少表明它是线程安全的。