title: Simplest way to do a fire and forget method in C#?
body: <p>I saw in WCF they have the <code>[OperationContract(IsOneWay = true)]</code> attribute.  But WCF seems kind of slow and heavy just to do create a nonblocking function.  Ideally there would be something like  static void nonblocking <code>MethodFoo(){}</code>, but I don't think that exists.</p>
  
  <p>What is the quickest way to create a nonblocking method call in C#?</p>
  
  <p>E.g.</p>
  
  <pre><code>class Foo
  {
      static void Main()
      {
          FireAway(); //No callback, just go away
          Console.WriteLine("Happens immediately");
      }
  
      static void FireAway()
      {
          System.Threading.Thread.Sleep(5000);
          Console.WriteLine("5 seconds later");
      }
  }
  </code></pre>
  
  <p><strong>NB</strong>: Everyone reading this should think about if they actually want the method to finish. (See #2 top answer)  If the method has to finish, then in some places, like an ASP.NET application, you will need to do something to block and keep the thread alive. Otherwise, this could lead to "fire-forget-but-never-actually-execute", in which case,of course, it would be simpler to write no code at all. (<a href="https://github.com/StephenCleary/AspNetBackgroundTasks" rel="noreferrer">A good description of how this works in ASP.NET</a>)</p>