title: Multiple Instances of same Application as a Windows Service?
body: <p>I have an application that manages the heavy processing for my project, and need to convert it to a "Windows Service."  I need to allow running multiple <strike>versions</strike> instances of the application processing, which seems to be a fairly normal requirement.</p>
  
  <p>I can see at least three approaches to do this:</p>
  
  <ol>
  <li>Create a single installed directory (EXE, DLLs, config) but install as multiple <em>Services</em> instances from it.</li>
  <li>Have a single <em>Services</em> instance spawn multiple instances of itself after launching, a la Apache.</li>
  <li>Have a single <em>Services</em> instance spawn multiple threads that work within the same process space.</li>
  </ol>
  
  <p>My intention was approach #1, but I kept tripping over the limitations, both in design and especially documentation for <em>Services</em>:</p>
  
  <ul>
  <li>Are parameters <em>ever</em> passed to <strong>OnStart()</strong> by the normal Services mechanisms on an unattended system? If so, when/why?</li>
  <li>Passing run-time parameters via the <em>ImageKey</em> registry seems a kludge, is there a better mechanism?</li>
  <li>I got the app to install/uninstall itself as a pair of services ("XYZ #1", "XYZ #2", ...), using the <em>ImageKey</em> to hand it a command line parameter instance number ("-x 1", "-x 2") but I was missing something.  When attempting to start the service, it would fail with "<em>The executable program that this service is configured to run in does not implement the service</em>.</li>
  </ul>
  
  <p>So, the questions:</p>
  
  <ol>
  <li>Is there a concise description of what happens when a service starts, specifically for those situations where the <em>ServiceName</em> is not hard-coded (see Q above).</li>
  <li>Has anyone used approach #1 successfully?  Any comments?</li>
  </ol>
  
  <p><em>NOTE:</em> I've side-stepped the problem by using approach #3, so I can't justify much time figuring this out.   But I thought someone might have information on how to implement #1 -- or good reasons why it isn't a good idea.</p>
  
  <p><strong>[Edit]</strong> I originally had a 4th option (<em>install multiple copies of the application on the hard drive</em>) but I removed it because it just feels, um, hackish.  That's why I said "<em>at least three approaches</em>".</p>
  
  <p>However, unless the app is recompiled, it must dynamically set its ServiceName, hence that has the solution to the third bullet/problem above.  So, unless an instance needed to alter it's install files, #1 should work fine with <em>N</em> config files in the directory and a registry entry indicating which the instance should use.</p>