title: asynchronous console application or Service?
body: <p>I'm trying to create a C# .net 4.5 console application that will run a loop continuously unless passed a command from the user. I don't want to check for an input from the user each time the loop completes because I expect this to run at least hours without user input, maybe even longer, however they should be able to type a command into the console at any time to be evaluated for how the loop should behave. </p>
  
  <p>To allow for user input at the same time the loop is running I believe I need to use threading such as <a href="/questions/tagged/async-await" class="post-tag" title="show questions tagged &#39;async-await&#39;" rel="tag">async-await</a>, however I'm quite new to programming and I'm not sure if threading is even the right approach. I've also recently learned of Services and since the user input is mostly stop and start, this may be the better approach.</p>
  
  <p>How should I modify my code below to implement asynchronous functionality allowing user input while running a continuous loop? Should this be a service instead as most user input is start and stop? </p>
  
  <p>I've included the code I've written so far:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          OptionMenu();
          Console.ReadLine();
      }        
  
      static void OptionMenu()
      {
          string command = "";
          Console.WriteLine("Please enter a command: \n");
          while (command != "exit")
          {
              command = Console.ReadLine().ToLower();
              switch (command)
              {
                  case "exit":
                      command = "exit";
                      break;
                  case "pause":
                      command = "Pause";
                      break;
                  case "start":                        
                      while (command != "Pause")
                      {
                          PrimaryWork();
                      }
                      break;
                  default:
                      Console.WriteLine("I'm sorry Dave, I'm afraid I can't do that");
                      break;
              }
          }
      }
  
      static void PrimaryWork()
      {
          Console.WriteLine("Results of PrimaryWork should be written to a repository");
          Thread.Sleep(5000);
      }
  }
  </code></pre>