title: C# TopShelf Service runs great with debugging; Incredibly slow without debugging
body: <p>Edit: This is still an issue but the program is not running slow as a service, it is running slow whenever NOT debugging.  Running the diagnostics withotu debugging produced the same slowness.  Peak cpu usage was 3%.  That being said, any help with why this application would run slower WITHOUT debugging would be incredibly helpful as I google down the answer :)</p>
  
  <p>Using C# and nuget'd topshelf, I have made a filewatcher/mover.  There is an instance of filesystemwatcher which performs a long set of logic against a text document (between 100 kb > 8 MB).  As it reads this text document (on a UNC network location) it will move the lines to one of 2 output files.</p>
  
  <p>While I run the application through Visual Studios 2015 Community in debug mode or release mode, all the file actions and movement are as instant as they can get.  Satisfied, I installed the application as a service on the same local machine.  I turn on the service, key the trigger, and it starts moving the text files....  50 kb every couple seconds.</p>
  
  <p>1 MB file is taking a few minutes to parse through when it took a whopping 10 seconds when run through Visual Studios.  The service is logged in as me, the same user in Visual Studio.  </p>
  
  <p>Any ideas?  I have used topshelf for 3-4 other services, all utilizing filesystemwatcher or System.IO.FILE library (using the file library).</p>
  
  <p>I can post some code if needed, just a bunch of if statements as it iterates through each line of text.  The key issue being:  works great from VS, not as a service.  Why??</p>
  
  <p>P.S.  Just noticed that it took >4 minutes to move 1.4 mb's all to another file line by line, but went through all the logic after the move within the same SECOND. </p>
  
  <p>I will post the snippet of topshelf configuration I am using, as it is not much:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          HostFactory.Run(hostConfigurator =&gt;
          {
              hostConfigurator.Service&lt;Service&gt;(serviceConfigurator =&gt;
              {
                  serviceConfigurator.ConstructUsing(name =&gt; new ASNWatcher());
                  serviceConfigurator.WhenStarted(tc =&gt; tc.Start());
                  serviceConfigurator.WhenStopped(tc =&gt; tc.Stop());
              });
              hostConfigurator.RunAsLocalSystem();
  
              hostConfigurator.SetDescription("HighRisk ASN Watcher");
              hostConfigurator.SetDisplayName("HighRiskASNWatcher");
              hostConfigurator.SetServiceName("HighRiskASNWatcher");
          });
      }
  </code></pre>
  
  <p>(yes, it says local system, I changed it post install to a proper user.)</p>
  
  <p>Adding code that does the reading; very lite.</p>
  
  <p>I am adding the piece of code that does the splitting:</p>
  
  <pre><code>     foreach (string line in File.ReadAllLines(fullPath))
              {
                  if (line.StartsWith("ASIAUD"))
                  {
                      foreach (var field in fileHelper856AUD.ReadString(line))
                      {
                          if (field.TradeID.TrimEnd() != TradeID &amp;&amp; field.TradeID.TrimEnd() != CatalogTradeID)
                          {
                              logger.Info("Found thisTrade ID:  " + field.TradeID.TrimEnd());
                              thisorder = true;
                          }
                          else
                          {
                              logger.Info("Found thatTrade ID:  " + field.TradeID.TrimEnd());
                              thisorder = false;
                          }
                      }
                  }
                  if (thisorder )
                  {
                      try
                      {
  
                          File.AppendAllText(newfile1, line + Environment.NewLine);
                      }
                      catch (Exception e)
                      {
                          //write to log,  also send an email alerting IT.
                      }
                  }
                  else
                  {
                      File.AppendAllText(newfile2, line + Environment.NewLine);
                  }
              }
              logger.Info("File Split Complete.  Deleting Original File...");
              File.Delete(fullPath);
  </code></pre>