title: Using all cores in pc with c#
body: <p>*Please note that I am just testing to understand this. </p>
  
  <p>I am trying to use all the cores of my computer with the <code>Parallel.For()</code> method. This is working just fine, but when I am trying the same method with a normal for loop it is going much faster. The parallel method is taking 16 sec and the normal method is only taking 6 sec.</p>
  
  <p>I hope you can tell me what I am doing wrong here. </p>
  
  <h2>Updated code</h2>
  
  <pre><code>        DateTime parallelStart = new DateTime();
          DateTime parallelFinish = new DateTime();
          DateTime singeStart = new DateTime();
          DateTime singeFinish = new DateTime();
          parallelStart = DateTime.Now;
          int inputData = 0;
  
          Parallel.For(0, 1000000000, i =&gt;
          {
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
          });
  
          parallelFinish = DateTime.Now;
          singeStart = DateTime.Now;
  
          for (int i = 0; i &lt; 1000000000; i++)
          {
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
              inputData = inputData++;
          }
  
          singeFinish = DateTime.Now;
          MessageBox.Show("Parallel execution time: " + (parallelFinish - parallelStart).Seconds + "\n" +
                          "Singe execution time: " + (singeFinish - singeStart).Seconds);
  </code></pre>
  
  <h2>First code:</h2>
  
  <pre><code>DateTime parallelStart = new DateTime();
  DateTime parallelFinish = new DateTime();
  DateTime singeStart = new DateTime();
  DateTime singeFinish = new DateTime();
  parallelStart = DateTime.Now;
  
  Parallel.For(0, 2000000000, i =&gt;
  {
      var inputData = 0;
  });
  
  parallelFinish = DateTime.Now;
  singeStart = DateTime.Now;
  
  for (int i = 0; i &lt; 2000000000; i++)
  {
      var inputData = 0;
  }
  
  singeFinish = DateTime.Now;
  MessageBox.Show("Parallel execution time: " + (parallelFinish - parallelStart).Seconds + "\n" + "Singe execution time: " + (singeFinish - singeStart).Seconds);
  </code></pre>