IEnumerator <T> IEnumerable <T> .GetEnumerator() { // instead of returning an unsafe enumerator, // we wrap it into our thread-safe class var enumerator = new SafeEnumerator <T>(_lock); enumerator.SetList(Items.GetEnumerator()); return(enumerator); }
/// <summary> /// GetEnumerator implementation for thread safety /// </summary> /// <returns></returns> IEnumerator <T> IEnumerable <T> .GetEnumerator() { // We have to wrap the unsafe enumerator into a thread-safe class // And then return it var enumerator = new SafeEnumerator <T>(_lock); enumerator.SetList(Items.GetEnumerator()); return(enumerator); }