title: Creating an async webservice method
body: <p>I've tried to read up on async methods and am now trying to create my own async method. The method is a webservice call that returns a list of error logs. I'm not sure that I've understood correctly so I thought I'd share my code to see if I should do anything different.</p>
  
  <p>All I want the code to do is return a list of errorlogs by calling a method <em>GetAllErrorLogs()</em>, that is a synchronized method. Since it can take a second to fetch all the error logs I want to have the opportunity to do other stuff once I called the <em>GetAllErrorLogs()</em> method. Here is the code.</p>
  
  <pre><code>[WebMethod]
  public async Task&lt;List&lt;ErrorLog&gt;&gt; GetAllErrorLogs()
  {
      List&lt;ErrorLog&gt; errorLogs = new List&lt;ErrorLog&gt;();
  
      await System.Threading.Tasks.Task.Run(() =&gt; {
          errorLogs = ErrorLogRepository.GetAllErrorLogs();
      });
  
  
      if (errorLogs == null)
          return new List&lt;ErrorLog&gt;();
  
      return errorLogs;
  }
  </code></pre>
  
  <p>Thanks!</p>