title: How to start a Process in a Thread
body: <hr>
  
  <p><strong>FURTHER EDIT</strong>
  <em>the following is not production code - I'm just playing around with a couple of classes trying to figure out how I run processes within threads - or even if that is viable. I've read various definitions on MSDN but am a newbie to threads and processes so any further definitive references to articles would be appreciated</em></p>
  
  <hr>
  
  <p>this is fine...</p>
  
  <pre><code>class Program {
      static void Main(string[] args) {
  
          Notepad np = new Notepad();
          Thread th = new Thread(new ThreadStart(np.startNPprocess));
          th.Start();
  
          Console.WriteLine("press [enter] to exit");
          Console.ReadLine();
      }
  }
  
  public class Notepad {
  
      public void startNPprocess() {
  
          Process pr = new Process();
          ProcessStartInfo prs = new ProcessStartInfo();
          prs.FileName = @"notepad.exe";
          pr.StartInfo = prs;
          pr.Start();     
  
      }
  }
  </code></pre>
  
  <p>this isn't...</p>
  
  <pre><code>class Program {
      static void Main(string[] args) {
  
  
          Process pr = new Process();
          ProcessStartInfo prs = new ProcessStartInfo();
          prs.FileName = @"notepad.exe";
          pr.StartInfo = prs;
  
          ThreadStart ths = new ThreadStart(pr.Start);
          Thread th = new Thread(ths);
          th.Start();
  
  
          Console.WriteLine("press [enter] to exit");
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>Why does the second not do the same as the first? In the second script I'm trying to pass <code>Process.Start</code> using the Threadstart delegate ...I thought this would be ok as its a <code>void</code> method?
  Is the first script the only option or can I change the second slightly so that it effectively does the same job as the first i.e start an instance of Notepad in a specified thread?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>Some background as to <em>why</em> I'm playing around with this code: ultimately I need to build an application which will be running several Excel processes simultaneously. These processes can be troublesome when VBA errors as it results in a dialogbox. So I thought if each process was running in a thread then if a particular thread has been running for too long then I could kill the thread. I'm a newbie to Threads/Processes so basically playing around with possibilities at the moment.</p>