title: Out of memory exception while using threads
body: <p>I have the following algorithm ,</p>
  
  <pre><code>private void writetodb()
  {
      using(var reader = File.OpenRead("C:\Data.csv");
      using(var parser = new TextFieldParser(reader))
      { 
          //Do some opeartions
          while(!parser.EndOfData)
          {
              //Do operations
              //Take 500 rows of data and put it in dataset
              Thread thread = new thread(() =&gt; WriteTodb(tablename, set));
              thread.Start();
              Thread.Sleep(5000);
          }
      }
  }
  
  public void WriteTodb(string table, CellSet set)
  {
      //WriteToDB
      //Edit: This statement will write to hbase db in hdinsight
      hbase.StoreCells(TableName, set);
  }
  </code></pre>
  
  <p>This method works absolutely fine until <strong>500 mb of data</strong> but after that it fails saying <code>Out of memory exception</code>.</p>
  
  <p>I am pretty much sure that it is because of threads but using threads is mandatory and I cant change the architecture.<br>
  Can anybody tell me what modifications I have to make in thread programming in the above program to avoid memory exception.</p>