title: C# ASP.NET Core Fire and forget
body: <p>I have a sync controller method </p>
  
  <pre><code>    public IActionResult Action(int num)
      {
          //operations-1
  
          Task.Run(() =&gt; DoWork(num));
  
          //operations-2
          int a = num + 123;
          return Ok(a);
      }
  </code></pre>
  
  <p>and DoWork method</p>
  
  <pre><code>    private bool DoWork(int num)
      {
          //operations
  
          return true;
      }
  </code></pre>
  
  <p>What I'm trying to do is to run DoWork method in background when calling that endpoint from Postman, but I want to get result in Postman and then debug DoWork method (from breakpoint in DoWork method) - is it possible?</p>
  
  <p>For that moment, controller action and DoWork() are executing simultaneously but when I reach </p>
  
  <pre><code>return Ok(a);
  </code></pre>
  
  <p>applications waits for DoWork instead of returning value. I have tried also</p>
  
  <pre><code>Task.Factory.StartNew(() =&gt; DoWork());
  ThreadPool.QueueUserWorkItem(o =&gt; DoWork());
  </code></pre>
  
  <p>but result is the same.</p>
  
  <p>I want DoWork method to return value but that value is not neccessary by controller action method - it will be used in different place, not connected with that.</p>