Question: ```
public static class People
{
      List<string> names {get; set;}
}

public class Threading
{
     public static async Task DoSomething()
     { 
         var t1 = new Task1("bob");
         var t2 = new Task1("erin"); 
         await Task.WhenAll(t1,t2);  
     }
     private static async Task Task1(string name)
     {
         await Task.Run(() =>
         {
            if(People.names == null) People.names = new List<string>();
            Peoples.names.Add(name);
         }
     }
}

```

Is that dangerous to initialize a list within a thread? Is it possible that both threads could initialize the list and remove one of the names? 

So I was thinking of three options:

1. Leave it like this since it is simple - only if it is safe though
2. Do same code but use a concurrentBag - I know thread safe but is initialize safe
3. Using [DataMember(EmitDefaultValue = new List())] and then just do .Add in Task1 and not worry about initializing. But the only con to this is sometimes the list wont need to be used at all and it seems like a waste to initialize it everytime.

Answer: 
Okay so what I figured worked best for my case was I used a lock statement.

```
public class Class1
{ 

  private static Object thisLock = new Object();

  private static async Task Task1(string name)
  {
      await Task.Run(() =>
      {
          AddToList(name);
      }
  }

  private static AddToList(string name)
  {
      lock(thisLock)
      {
          if(People.names == null) People.names = new List<string>();
          People.names.Add(name);
      }
  }
}

public static class People
{
    public static List<string> names {get; set;}
}

```
for a simple case like this the easiest way to get thread-safety is using the `lock` statement:

```
public static class People
{
  static List<string> _names = new List<string>();

  public static void AddName(string name)
  {
     lock (_names)
     {
        _names.Add(name);
     }
  }

  public static IEnumerable<string> GetNames()
  {
     lock(_names)
     {
        return _names.ToArray();
     }
  }
}

public class Threading
{
     public static async Task DoSomething()
     { 
         var t1 = new Task1("bob");
         var t2 = new Task1("erin"); 
         await Task.WhenAll(t1,t2);  
     }
     private static async Task Task1(string name)
     {
         People.AddName(name);
     }
}

```

of course it's not very usefull (why not just add without the threads) - but I hope you get the idea.

If you don't use some kind of lock and concurrently read and write to a `List` you will most likely get an `InvalidOperationException` saying the collection has changed during read.

Because you don't really know when a user will use the collection you might return the easiest way to get thread-saftey is copying the collection into an array and returning this.

If this is not practical (collection to large, ..) you have to use the classes in [System.Collections.Concurrrent](http://msdn.microsoft.com/de-de/library/system.collections.concurrent%28v=vs.110%29.aspx) for example the [BlockingCollection](http://msdn.microsoft.com/de-de/library/dd267312%28v=vs.110%29.aspx) but those are a bit more involved.