title: An example of parallel programming with multithreading
body: <p>So I think I understand the overview concept of parallel programming and multithreading, but I was wondering if you can achieve multi-process multi-threaded applications.  If that makes sense, when looking at some of the descriptions of multi-threading it can be run on one processor but if you can process on multiple cores using parallel can you also multi-thread on multiple cores? If you can, could someone show me a simple example of this, using a <code>for loop</code> maybe?</p>
  
  <p>Multi-threaded example: </p>
  
  <pre><code>public class Test
  {
      static void Main()
      {
          Counter foo = new Counter();
          ThreadStart job = new ThreadStart(foo.Count);
          Thread thread = new Thread(job);
          thread.Start();
  
          for (int i=0; i &lt; 5; i++)
          {
              Console.WriteLine ("Main thread: {0}", i);
              Thread.Sleep(1000);
          }
      }
  }
  
  public class Counter
  {
      public void Count()
      {
          for (int i=0; i &lt; 10; i++)
          {
              Console.WriteLine ("Other thread: {0}", i);
              Thread.Sleep(500);
          }
      }
  }
  </code></pre>
  
  <p>Example of parallel:</p>
  
  <pre><code>int n = ...
  Parallel.For(0, n, i =&gt;
  {
     // ... 
  });
  </code></pre>