title: C# Singleton thread safe
body: <p>I have a singleton class similar to this</p>
  
  <pre><code>public class Singleton
  {
      private static Singleton m_instance;
      private Timer m_timer;
      private static List&lt;CustomObject&gt; m_cacheObjects;
  
      private Singleton()
      {    
          m_cacheObjects = new List&lt;CustomObject&gt;();
          m_timer= new Timer(MyTimerCallBack, 
                             null, 
                             TimeSpan.FromSeconds(60), 
                             TimeSpan.FromSeconds(60));           
      }
  
      public static Singleton Instance
      {
          get
          {
              if (m_instance == null)
              {
                  m_instance = new Singleton();
              }
              return m_instance;
          }
      }
  
      private void MyTimerCallBack(object state)
      {
          //******** Update the list by interval here ******************
  
          m_cacheObjects = UpdateTheList();
      }
  
      public void CallMe()
      {
          foreach (CustomObject obj in m_cacheObjects)
          {
              // do something here based on obj
  
              // The question is, does the m_cacheObjects is thread safe??
              // what happen if the m_cacheObjects is changed
              // during the loop interation?
          }
      }
  }
  </code></pre>
  
  <p>The CallMe method will be called by web service:</p>
  
  <pre><code>  [WebMethod]
      public void CallMeWebService()
      {
          Singleton.Instance.CallMe();
      }
  </code></pre>
  
  <p>The questions:
  1) Is the m_cacheObjects is thread safe? what happen if the m_cacheObjects is changed(because of the timer) during the loop interation (in the CallMe() )? </p>
  
  <p>2) Is a new thread will be created when the Webservice CallMeWebService() is being called?</p>