How do I refactor this IEnumerable<T> to be thread-safe?

Posted by DayOne on Stack Overflow See other posts from Stack Overflow or by DayOne
Published on 2010-04-28T09:20:54Z Indexed on 2010/04/28 9:23 UTC
Read the original article Hit count: 253

Filed under:
|

I am looking at Skeet's AtomicEnumerable but I'm not sure how to integrate it into my current IEnumerable exmaple below (http://msmvps.com/blogs/jon_skeet/archive/2009/10/23/iterating-atomically.aspx)

Basically I want to foreach my blahs type in a thread-safe way.

thanks

public sealed class Blahs :  IEnumerable<string>
{
    private readonly IList<string> _data = new List<string>() { "blah1", "blah2", "blah3" };

    public IEnumerator<string> GetEnumerator()
    {
        return _data.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about thread-safety