title: reading a csv file with a million rows in parallel in c#
body: <p>I have a CVS file with over 1 Million rows of data. I am planning to read them in parallel to improve efficiency. Can I do something like the following or is there a more efficient method?</p>
  
  <pre><code>namespace ParallelData
  {
  public partial class ParallelData : Form
  {
      public ParallelData()
      {
          InitializeComponent();
      }
  
      private static readonly char[] Separators = { ',', ' ' };
  
      private static void ProcessFile()
      {
          var lines = File.ReadLines("BigData.csv");
          var numbers = ProcessRawNumbers(lines);
  
          var rowTotal = new List&lt;double&gt;();
          var totalElements = 0;
  
          foreach (var values in numbers)
          {
              var sumOfRow = values.Sum();
              rowTotal.Add(sumOfRow);
              totalElements += values.Count;
          }
          MessageBox.Show(totalElements.ToString());
      }
  
      private static List&lt;List&lt;double&gt;&gt; ProcessRawNumbers(IEnumerable&lt;string&gt; lines)
      {
          var numbers = new List&lt;List&lt;double&gt;&gt;();
          /*System.Threading.Tasks.*/
          Parallel.ForEach(lines, line =&gt;
          {
              lock (numbers)
              {
                  numbers.Add(ProcessLine(line));
              }
          });
          return numbers;
      }
  
      private static List&lt;double&gt; ProcessLine(string line)
      {
          var list = new List&lt;double&gt;();
          foreach (var s in line.Split(Separators, StringSplitOptions.RemoveEmptyEntries))
          {
              double i;
              if (Double.TryParse(s, out i))
              {
                  list.Add(i);
              }
          }
          return list;
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          ProcessFile();
      }
  }
  }
  </code></pre>