title: How to run multiple tasks on specific multiple cores/processors simultaneously/synchronously
body: <p>I have multiple tasks and i need to run them on specific multiple cores or processors simultaneously.</p>
  
  <p>For Example, if i have two different tasks or just one task but will run it twice I want to run these two tasks on specific cores or processors simultaneously like task1 will run on processor1 and task2 will run on processor2 at the same time.</p>
  
  <p>I know how to run each specific processor but i do not know how to run them simultaneously. I was trying to use multithreading then task parallel library to run different tasks on specific processors at the same time but i failed.</p>
  
  <p>In below code, i was trying to use multithreading but it doesnt work or can i use task parallel library???</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Diagnostics;
  
  
  namespace ConsoleApplication14
  
  {
      class Program
  {
  
      public static double DumbCountSqr(int dumnum)
      {
  
          Random random = new Random();
          int randomNumber = random.Next(0, 10);
          double result = 0;
          for (int i = 1; i &lt; 10000; i++)
          {
              for (int j = 1; j &lt; 10000; j++)
              {
                  result += random.Next(0, 10) * Math.Sqrt(i) * Math.Sqrt(j) + Math.Abs(Math.Sqrt(i));
              }
          }
          return result;
      }
  
      public static void Main()
      {
  
          Thread t = new Thread(new ThreadStart(Go));
          t.Start();
  
  
          for (int i = 0; i &lt; 1; i++)
          {
  
              Process Proc = Process.GetCurrentProcess();
              long AffinityMask = (long)Proc.ProcessorAffinity;
  
              AffinityMask = 0x0004;//processor    3
              Proc.ProcessorAffinity = (IntPtr)AffinityMask;
  
              var result1 = DumbCountSqr(i);
              Console.WriteLine("result1 =  " + result1);
  
          }
      }
  
  
     public static void Go()
      {
  
          for (int i = 0; i &lt; 1; i++)
          {
  
                  Process Proc = Process.GetCurrentProcess();
                  long AffinityMask = (long)Proc.ProcessorAffinity;
  
                  AffinityMask = 0x0001;//processor    1
                  Proc.ProcessorAffinity = (IntPtr)AffinityMask;
  
                  var result2 = DumbCountSqr(i);
                  Console.WriteLine("result2 =  " + result2);
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>}</p>