Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.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

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
Vb.net 无法在CollectionChanged事件期间更改ObservableCollection_Vb.net_Silverlight_Methods - Fatal编程技术网

Vb.net 无法在CollectionChanged事件期间更改ObservableCollection

Vb.net 无法在CollectionChanged事件期间更改ObservableCollection,vb.net,silverlight,methods,Vb.net,Silverlight,Methods,问题是: 我有一个CollectionChanged处理程序方法: Private Sub LayersChanged(sender As Object, e As Collections.Specialized.NotifyCollectionChangedEventArgs) If e.ItemCollectionHasNewItems IsNot Nothing Then SomethingRelatedToE.execute

问题是:

我有一个CollectionChanged处理程序方法:

    Private Sub LayersChanged(sender As Object, e As Collections.Specialized.NotifyCollectionChangedEventArgs)
        If e.ItemCollectionHasNewItems IsNot Nothing Then
            SomethingRelatedToE.execute
        End If
    End Sub
我不能调用SomethingRelatedToE.excecute,因为它会影响e的集合,从而导致运行时错误

但是,如果LayersChanged方法已经完成,那么我可以从另一个方法调用SomethingRelatedToE.execute而不影响它


在LayerChanged方法完成后,是否有办法直接移动到另一个方法,例如Goto函数或其他解决方案?

不允许这种类型的操作,因为它通常会导致循环引用。在
CollectionChanged
事件中修改集合时,将再次引发该事件,该事件将再次修改集合

我不建议尝试解决这个问题,因为让集合自行修改是不寻常的。试着用另一种方法来做这件事

但是,如果需要,可以尝试使用
ThreadPool.QueueUserWorkItem
在另一个线程中执行任务。您仍然需要检查可能的循环引用,并观察比赛条件