title: Accessing the same string(StringBuilder) using multi-thread
body: <p>My problem is if I use multi-thread on the same string sometime </p>
  
  <p>the string won't get replace.(I wrote this on notepad so syntax may be </p>
  
  <p>wrong)</p>
  
  <p>using System.Thread ... Others ofcourse</p>
  
  <pre><code>class ....
  {
      private static StringBuild container = new StringBuilder();
  
      static void Main(...)
      {
      container.Append(Read From File(Kind of long));
      Thread thread1 = new Thread(Function1);
          Thread thread2 = new Thread(Function2);
      thread1.Start();
      thread2.Start();
      //Print out container
      }
  
      static void Function1
      {
      //Do calculation and stuff to get the Array for the foreach
      foreach (.......Long loop........)
      {
      container.Replace("this", "With this")
      }
      }
      //Same goes for function but replacing different things.
      static void Function2
      {
      //Do calculation and stuff to get the Array for the foreach
      foreach (.......Long loop........)
      {
      container.Replace("this", "With this")
      }
      }
  }
  </code></pre>
  
  <p>Now sometime some element does not get replace.
  So my solution to this is calling container.Replace on a different </p>
  
  <p>method and do a "lock" which work but is it the right way?</p>
  
  <pre><code>private class ModiflyString
  {
          public void Do(string x, string y)
              {
                  lock (this)
                  {
                      fileInput.Replace(x, y);
                  }
              }
  }
  </code></pre>