title: Keep application running all the time
body: <p>Basically I need my application to run from system start until system shutdown. I figured out the following approach:</p>
  
  <ol>
  <li>create MyApp.exe and MyService.exe</li>
  <li>MyApp should install MyService as a service</li>
  <li>MyService is supposed to run at startup and periodically check if MyApp is running. If it's not than start it.</li>
  </ol>
  
  <p>That's the code I wrote for my service:</p>
  
  <pre><code>protected override void OnStart(string[] args)
  {
      while(true)
      {
          int processesCount =
              Process.GetProcessesByName(Settings.Default.MyAppName).Count() +
              Process.GetProcessesByName(Settings.Default.MyAppName + ".vshost").Count() +
              Process.GetProcessesByName(Settings.Default.MyAppUpdaterName).Count();
  
          if(processesCount==0)
          {
              //restore
              var p = new Process { StartInfo = { FileName = Settings.Default.MyAppName, Arguments = "" } };
              p.Start();
          }
          else
          {
          }
  
          System.Threading.Thread.Sleep(3000);
      }
  }
  </code></pre>
  
  <ol>
  <li>How can I install this process so that it starts on windows start?</li>
  <li>I'm not sure if this infinite loop in OnStart method is a good idea. Is it?</li>
  <li>Is the general idea ok?</li>
  </ol>