Here’s the problem:
I have a CollectionChanged Handler Method:
Private Sub LayersChanged(sender As Object, e As Collections.Specialized.NotifyCollectionChangedEventArgs)
If e.ItemCollectionHasNewItems IsNot Nothing Then
SomethingRelatedToE.execute
End If
End Sub
I cant call SomethingRelatedToE.excecute because it effects e‘s collection which causes a runtime error.
However if the LayersChanged method has completed I can then call SomethingRelatedToE.execute from another method without effecting it.
Is there a way for me to directly move to another method after the LayersChanged method has finished, like a Goto function or another solution to this?
The reason this type of action isn’t allowed is because it will usually result in a circular reference. When the collection is modified in the
CollectionChangedevent, the event will once again be raised, which will again modify the collection.I would not recommend trying to work around this because it’s unusual to have a collection modify itself. Try thinking of a way to do it another way.
If you need to, though, you can try using
ThreadPool.QueueUserWorkItemto do your task in another thread. You’ll still want to check for possible circular references and watch for race conditions.