title: Synchronous Task Execution in C#
body: <p>I have a method in a Singleton class which will be called from different threads. But I need to execute them one by one. like </p>
  
  <p>The method ImageUtil.Instance.LoadImage(imageID) will be called from multiple threads. But I want to load image one by one. So at a time only one image will load.</p>
  
  <pre><code>public class ImageUtil
  {
      #region Singleton Implementation
      private ImageUtil()
      {
          taskList = new List&lt;Task&lt;object&gt;&gt;();
      }
  
      public static ImageUtil Instance { get { return Nested.instance; } }
  
      private class Nested
      {
          // Explicit static constructor to tell C# compiler
          // not to mark type as before field init
          static Nested()
          {
          }
  
          internal static readonly ImageUtil instance = new ImageUtil();
      }
  
      #endregion
  
      Queue&lt;Task&lt;Object&gt;&gt; taskList;
      bool isProcessing;
      public async Task&lt;Object&gt; LoadImage(String imageID)
      {
          //Here what I need to put to execute "return await LoadImageInternal(imageID);"
          //one by one. So that if one image is loading and mean time some other thread
          //calls this method then the last thread have to wait until current loading finish.
  
      }
      private async Task&lt;Object&gt; LoadImageInternal(String imageID)
      {
          //Business Logic for image retrieval.
      }
  }
  </code></pre>