title: The asynchronous method appears not to wait even though it contains "await" keyword in C#
body: <p>The asynchronous <code>SetAlarmLogToWebServiceAsync()</code> method appears not to wait even though it contains &quot;await&quot; keyword.</p>
  <p>The code below writes unexpected logs.</p>
  <pre><code>//Client Side
  private async void FrmMain_Load(object sender, EventArgs e)
  {
      await StartAllTasksAsync();
  }
  
  private async Task StartAllTasksAsync()
  {
      var task = SetAlarmLogToWebServiceAsync();
      return Task.WhenAll(task);
  }
  
  public async Task SetAlarmLogToWebServiceAsync()
  {
      while (true)
      {
          await Task.Delay(300);
          await _alarmLogManager.SetAlarmLogToWebServiceAsync();
      }
  }
  
  //Business Logic Side
  public async Task SetAlarmLogToWebServiceAsync()
  {
      var alarmLog = (await _alarmLogDal.GetListAsync()).FirstOrDefault();
      _logger.Verbose($&quot;AlarmLog was gotten from db. AlarmId: {alarmLog.AlarmId}&quot;);
      
      try
      {
          var serviceResult = await _webServiceDal.SetAlarmLogAsync(alarmLog);
          if (serviceResult &gt; 0)
          {
              _logger.Verbose($&quot;AlarmLog was sent to web service. AlarmId: {alarmLog.AlarmId}&quot;);
              var dbResult = await _alarmLogDal.UpdateServiceStatusAsync(alarmLog);
          }
      }
      catch (Exception ex)
      {
          _logger.Error($&quot;Error on sending AlarmLog to WebService. AlarmId: {alarmLog.AlarmId}&quot; +
              $&quot;\n    Exception message: {ex.Message}&quot;);
          await Task.Delay(3000);
      }
  }
  </code></pre>
  <p>The logs:</p>
  <pre><code>2020-11-19 12:09:50.718 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:51.490 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:51.863 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:52.230 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:52.563 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:52.888 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:53.215 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:53.567 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:53.935 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:54.300 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:54.678 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:55.031 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:55.384 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:55.735 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:56.060 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:56.386 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:56.716 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:57.047 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:57.371 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:57.700 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:58.030 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:58.382 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:58.738 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:59.073 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:59.482 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:09:59.809 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:00.138 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:00.468 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:00.833 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:01.200 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:11.202 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  2020-11-19 12:10:14.543 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:24.546 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  2020-11-19 12:10:27.907 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:28.725 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:29.057 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:29.390 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:29.715 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:30.043 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:30.408 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:30.754 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:31.114 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:31.493 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:31.864 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:32.189 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:32.516 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:32.841 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:33.169 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:33.498 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:43.502 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  2020-11-19 12:10:46.848 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:56.862 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  </code></pre>
  <p>I'm using Serilog for logging. The logger is being created like this:</p>
  <pre><code>public static Serilog.ILogger GetSerilogAsyncFileLogger(int retainedFileCountLimit = 2)
  {
      return new LoggerConfiguration()
          .WriteTo.Async(a =&gt;
          {
              a.File(
                  path: &quot;logs\\log.txt&quot;,
                  outputTemplate: &quot;{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}&quot;,
                  rollingInterval: RollingInterval.Day,
                  fileSizeLimitBytes: 500000000,
                  rollOnFileSizeLimit: true,
                  retainedFileCountLimit: retainedFileCountLimit);
          })
          .MinimumLevel.Verbose()
          .CreateLogger();
  }
  </code></pre>
  <p>The <code>SetAlarmLogToWebServiceAsync()</code> must await for all calls. I expected the logs below. How can i get the logs below?</p>
  <pre><code>2020-11-19 12:10:01.200 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:11.202 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  2020-11-19 12:10:01.200 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:11.202 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  2020-11-19 12:10:01.200 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:11.202 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  2020-11-19 12:10:01.200 +03:00 [VRB] AlarmLog was gotten from db. AlarmId: 86944
  2020-11-19 12:10:11.202 +03:00 [ERR] Error on sending AlarmLog to WebService. AlarmId: 86944
      Exception message: A task was canceled.
  </code></pre>