title: Topshelf - starting threads based on custom parameters
body: <p>I've made a topshelf webservice that uses custom parameter:</p>
  
  <pre><code>string department = null;
  
  // *********************Below is a TopShelf
  HostFactory.Run(hostConfigurator =&gt;
  {
      //Define new parameter
      hostConfigurator.ApplyCommandLine();                                                
      //apply it  
      hostConfigurator.AddCommandLineDefinition("department", f =&gt; { department = f; });
  
      Helpers.LogFile("xxx", "Got department:"+department);  
  
      hostConfigurator.Service&lt;MyService&gt;(serviceConfigurator =&gt;
      {
          //what service we are using
          serviceConfigurator.ConstructUsing(() =&gt; new MyService(department));
          //what to run on start
          serviceConfigurator.WhenStarted(myService =&gt; myService.Start());
          // and on stop             
          serviceConfigurator.WhenStopped(myService =&gt; myService.Stop());                 
      }
  
      hostConfigurator.RunAsLocalService();
  
      //****************Change those names for other
      string d = "CallForwardService_" + department;
  
      hostConfigurator.SetDisplayName(d);
      hostConfigurator.SetDescription("CallForward using Topshelf");
      hostConfigurator.SetServiceName(d);                
  });
  
  
  
  public class MyService
  {
      string depTask;
      public MyService(string d)
      {
          //***********************Three tasks for three different destinations
          depTask = d;
          _taskL = new Task(Logistics);
          _taskP = new Task(Planners);
          _taskW = new Task(Workshop);
          Helpers.LogFile(depTask, "started working on threads for "+d);   
  
          public void Start()
          {
              if (depTask == "logistics")
              {
                  _taskL.Start();
                  Helpers.LogFile(depTask, "proper thread selected");      
              }
          }
      }
  }
  </code></pre>
  
  <p>Where <code>Helpers.logfile</code> simply writes to text file. Aa you can see from the code above the parameter <code>department</code> is passed to the <code>MyService(string d)</code>.
  It all works fine when I'm debugging using i.e. the "-department:workshop" as debugging parameter. But when I'm trying to install the program as a service using
  <code>callforward.exe install -department:logistics</code> I do create service <code>callforwardservice_logistics</code> bu when I check the log the parameter hasn't been passed to the MyService.</p>
  
  <p>What am I doing wrong?</p>