title: How to make delay between two methods execution?
body: <p>I use async/await to make a delay between the method execution.</p>
  
  <p>There is a code</p>
  
  <pre><code>public bool DoPerformCommandOnClient(string commandStr, bool isOnPath, string folderPath, string ext, string doneMessage, string excludeString)
  {
      Task.Run(() =&gt; DoOpenProgressBarWindowWithDelay(2000));
      return GetLogic().PerformCommandOnClient(commandStr, isOnPath, folderPath, ext, doneMessage, excludeString);
  }
  </code></pre>
  
  <pre><code>public async void DoOpenProgressBarWindowWithDelay(int delay)
  {
      BeginInvoke((Action)(() =&gt; {
          DoOpenProgressBarWindow();
      }));
      await Task.Delay(delay);
  }
  </code></pre>
  
  <p>So, I would like to execute <code>DoPerformCommandOnClient</code> method then after 2 sec delay execute next line </p>
  
  <pre><code>return GetLogic().PerformCommandOnClient(commandStr, isOnPath, folderPath, ext, doneMessage, excludeString);
  </code></pre>
  
  <p>But instead this method <code>DoPerformCommandOnClient</code> executes without delay.</p>
  
  <p>Then I tried to add <code>Thread.Sleep(2000)</code> between two lines</p>
  
  <pre><code>public bool DoPerformCommandOnClient(string commandStr, bool isOnPath, string folderPath, string ext, string doneMessage, string excludeString)
  {
      DoOpenProgressBarWindow();
      Thread.Sleep(2000);
      return GetLogic().PerformCommandOnClient(commandStr, isOnPath, folderPath, ext, doneMessage, excludeString);
  }
  </code></pre>
  
  <p>But this approach stops my UI, I don't need to stop my UI.</p>
  
  <p>So, the question is how to make a delay between two methods?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>now code looks like this</p>
  
  <pre><code>public bool DoPerformCommandOnClient(string commandStr, bool isOnPath, string folderPath, string ext, string doneMessage, string excludeString)
  {
      Task.Run(() =&gt; DoOpenProgressBarWindowWithDelay(2000)).Wait();
      return GetLogic().PerformCommandOnClient(commandStr, isOnPath, folderPath, ext, doneMessage, excludeString);
  }
  
  public async void DoOpenProgressBarWindowWithDelay(int delay)
  {
      BeginInvoke((Action)(() =&gt; {
          DoOpenProgressBarWindow();
      }));
      await Task.Delay(delay).ConfigureAwait(false);
  }
  </code></pre>
  
  <p><strong>EDIT2</strong></p>
  
  <p>Now code looks like this</p>
  
  <pre><code>public async Task&lt;bool&gt; DoPerformCommandOnClient(string commandStr, bool isOnPath, string folderPath, string ext, string doneMessage, string excludeString)
          {
              await DoOpenProgressBarWindowWithDelay(2000).ConfigureAwait(false);
              return GetLogic().PerformCommandOnClient(commandStr, isOnPath, folderPath, ext, doneMessage, excludeString);
          }
  
          public async Task&lt;bool&gt; DoOpenProgressBarWindowWithDelay(int delay)
          {
              BeginInvoke((Action)(() =&gt;
              {
                  DoOpenProgressBarWindow();
              }));
  
              await Task.Delay(delay).ConfigureAwait(false);
  
              return true;
          }
  </code></pre>
  
  <p><strong>EDIT3</strong></p>
  
  <pre><code>public async Task&lt;bool&gt; DoPerformCommandOnClient(string commandStr, bool isOnPath, string folderPath, string ext, string doneMessage, string excludeString)
          {
              await DoOpenProgressBarWindowWithDelay(2000).ConfigureAwait(false);
              return GetLogic().PerformCommandOnClient(commandStr, isOnPath, folderPath, ext, doneMessage, excludeString);
          }
  
          public async Task DoOpenProgressBarWindowWithDelay(int delay)
          {
              BeginInvoke((Action)(() =&gt;
              {
                  DoOpenProgressBarWindow();
              }));
  
              await Task.Delay(delay).ConfigureAwait(false);
          }
  </code></pre>
  
  <p>There is a way how I call this method</p>
  
  <pre><code>if (!m_MyManagerMainForm.DoPerformCommandOnClient(cmd1, true, sourcePath, "bmp", "ColorImageDone", "_M"))
              {
                  RestoreGUIFromCalibration();
                  return;
              }
  </code></pre>
  
  <p>but it doesn't work, it says that I can't implicitly convert <code>Task&lt;bool&gt; to bool</code></p>