title: If my interface must return Task what is the best way to have a no-operation implementation?
body: <p>In the code below, due to the interface, the class <code>LazyBar</code> must return a task from its method (and for argument's sake can't be changed). If <code>LazyBar</code>s implementation is unusual in that it happens to run quickly and synchronously - what is the best way to return a No-Operation task from the method?</p>
  <p>I have gone with <code>Task.Delay(0)</code> below, however I would like to know if this has any performance side-effects if the function is called a <em>lot</em> (for argument's sake, say hundreds of times a second):</p>
  <ul>
  <li>Does this syntactic sugar un-wind to something big?</li>
  <li>Does it start clogging up my application's thread pool?</li>
  <li>Is the compiler cleaver enough to deal with <code>Delay(0)</code> differently?</li>
  <li>Would <code>return Task.Run(() =&gt; { });</code> be any different?</li>
  </ul>
  <p>Is there a better way?</p>
  <pre><code>using System.Threading.Tasks;
  
  namespace MyAsyncTest
  {
      internal interface IFooFace
      {
          Task WillBeLongRunningAsyncInTheMajorityOfImplementations();
      }
  
      /// &lt;summary&gt;
      /// An implementation, that unlike most cases, will not have a long-running
      /// operation in 'WillBeLongRunningAsyncInTheMajorityOfImplementations'
      /// &lt;/summary&gt;
      internal class LazyBar : IFooFace
      {
          #region IFooFace Members
  
          public Task WillBeLongRunningAsyncInTheMajorityOfImplementations()
          {
              // First, do something really quick
              var x = 1;
  
              // Can't return 'null' here! Does 'Task.Delay(0)' have any performance considerations?
              // Is it a real no-op, or if I call this a lot, will it adversely affect the
              // underlying thread-pool? Better way?
              return Task.Delay(0);
  
              // Any different?
              // return Task.Run(() =&gt; { });
  
              // If my task returned something, I would do:
              // return Task.FromResult&lt;int&gt;(12345);
          }
  
          #endregion
      }
  
      internal class Program
      {
          private static void Main(string[] args)
          {
              Test();
          }
  
          private static async void Test()
          {
              IFooFace foo = FactoryCreate();
              await foo.WillBeLongRunningAsyncInTheMajorityOfImplementations();
              return;
          }
  
          private static IFooFace FactoryCreate()
          {
              return new LazyBar();
          }
      }
  }
  </code></pre>