title: How to prevent a async task method get called concurrently
body: <p>I have a async task method which will be accessed on both foreground and background. In foreground, where user call this method via a button whereas in the background I have a timer triggering the method in some interval.</p>
  
  <p>I tried put lock but it gives exception await can not be inside the lock statement.</p>
  
  <pre><code>    public static async Task&lt;CommonResult&lt;IEnumerable&lt;AttendanceDTO&gt;&gt;&gt; DownloadAttendanceAsync(string selectedDate, int siteId)
      {
          try
          { 
              if (new AttendanceBLL().IsLocalDataAvailable(siteId, DateTime.Parse(selectedDate)))
                  return new CommonResult&lt;IEnumerable&lt;AttendanceDTO&gt;&gt;() { IsSuccess = true, Data = null };
  
              var queue = new EntityQueueBLL();
              //var latestUpdatedOn = queue.GetMaxUpdated(siteId, EntityIDEnum.Attendance);
              var url = string.Format(Constants.PathPullAttendance, selectedDate, siteId);
              var result = await new HttpRequestClient().GetRequest&lt;IEnumerable&lt;AttendanceDTO&gt;&gt;(url);
  
              if (!result.IsSuccess)
                  return new CommonResult&lt;IEnumerable&lt;AttendanceDTO&gt;&gt;() { IsSuccess = false, Data = null, ErrorMessage = result.ErrorMessage };
  
              if (result.Data != null &amp;&amp; result.Data.Count() &gt; 0)
              {
                  var maxUpdatedOn = result.Data.Max(x =&gt; DateTime.Parse(x.UpdatedOn));
                  queue.Add(siteId, result.Data, result.Data.Count(), EntityIDEnum.Attendance, EntityType.Attendance, maxUpdatedOn);
              }
  
              return new CommonResult&lt;IEnumerable&lt;AttendanceDTO&gt;&gt; { IsSuccess = true, Data = result.Data }; 
          }
          catch (Exception e)
          {
              return new CommonResult&lt;IEnumerable&lt;AttendanceDTO&gt;&gt; { IsSuccess = false, Data = null, ErrorMessage = "Download Error" };
          }
      }
  </code></pre>