title: C# ASP.NET Core API Async/await VS Result
body: <p>I'm a bit confused on best practices with c# and tasks.<br />
  When I was taught c# and tasks it was always an async function that awaits a task. But recently I have been doing some research and found some people who say otherwise. They also say that limiting usage of async and await can improve performance and Ram usage.</p>
  <p>For example in <a href="https://stackoverflow.com/questions/35201881/should-i-use-async-await-for-every-method-that-returns-a-task">This Stackoverflow post</a> It says you shouldn't always await every task but the example isnt for an ASP.NET API and there isn't any previous data used to get the new data.
  <a href="https://riptutorial.com/csharp/example/16320/returning-a-task-without-await" rel="nofollow noreferrer">This post</a> also is in favor of not always awaiting every task. But again the example is a simple task being passed through.</p>
  <p>So my question is for cases when there is another task on which the second task must wait. Can you use <code>.Result</code> or is it better us use async/await. Because I heard <code>.Result</code> is blocking the current thread.
  But I can't see how the current thread would not be blocked by the await since the output of the first statement is needed for the second statement.</p>
  <p>Example without async/await</p>
  <pre><code>public Task&lt;User&gt; SaveUser(User user) 
  {
      var dbUser = _userRepository.GetByUid(user.Id).Result;
      if(dbUser == null) {
          dbUser = new User();
          dbUser.Id = Guid.NewGuid();
      }
      dbUser.Name = user.Name;
  
      return _userRepository.Save(dbUser);
  
  }
  </code></pre>
  <p>Example with async/await</p>
  <pre><code>public async Task&lt;User&gt; SaveUser(User user) 
  {
      var dbUser = await _userRepository.GetByUid(user.Id);
      if(dbUser == null) {
          dbUser = new User();
          dbUser.Id = Guid.NewGuid();
      }
      dbUser.Name = user.Name;
  
      return await _userRepository.Save(dbUser);
  
  }
  </code></pre>
  <p>Note: I also heard that when using an UI, it's important that UI related tasks are awaited but this would be for API's.</p>