Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
ObservableCollection and Thread Safety
posted

I have a thread safe implementation of the ObservableCollection that locks when adding, removing and firing the CollectionChanged event (in case a listener would like to iterate it).

Now I'm wondering, if XamChart that binds to this collection through a Series object migth initiate an enumeration without recieving the CollectionChanged event, iterating it without locking it.
Is there a way to make sure this doesn't happen, or do I have to implement the IEnumerable interface myself, and return the enumerator of a copy of the collection in the GetEnumerator method.

Troels

Parents
No Data
Reply
  • 28496
    Offline posted

    the xamchart will certainly enumerate through your collection during databinding.  it won't modify it, though. 

    i don't know of any pattern to sync lock enumeration, since even if you implement IEnumerable and IEnumerator, you still don't know when the caller has started, finished, or broken out of the loop.

Children
No Data