title: StateHasChanged() re-render the component one time out of two
body: <p>I'm making a Blazor Server Side project and I wanted to make a button that desactivate after a click, but without using the <code>disabled</code> attribute of <code>&lt;button&gt;</code>. The code is pretty simple :</p>
  
  <pre><code>@functions {
  
      LogInForm logInForm = new LogInForm();
      bool IsDisabled;
      SignInResult result;
  
      protected override void OnInitialized()
      {
          IsDisabled = false;
      }
  
      async Task TryLogIn()
      {
          IsDisabled = true;
          StateHasChanged();
          result =  await _LogInService.TryLogIn(logInForm);
          Console.WriteLine("Logging status : " + (result.Succeeded ? "Sucess" : "Failure"));
          IsDisabled = false;
          StateHasChanged();
      }
  
  }
  </code></pre>
  
  <p>For odd reasons, the first <code>StateHasChanged</code> isn't triggering but the second does re-render the page. It can be quite easily testes by going in Debug mode and entering into the <code>StateHasChanged()</code> method. On second time call it does stop on the HTML code after going into the method but not the first time.</p>
  
  <p>Why so ?</p>
  
  <p><strong>NB :</strong> I'm not looking for any workaround using <code>Task.Delay</code> or <code>Task.Run(...)</code> only, as it exist a race condition between those threads and the UI refresh thread, and so it is not a reliable solution. I'm looking for answers on the <code>StateHasChanged()</code> behaviour or a workaround by using events like <code>PropertyChanged</code> or <code>EventCallback</code> and putting the button as a child component.</p>
  
  <p><strong>Edit :</strong> After some testing, it seems that <code>StateHasChanged()</code> only triggers the re-render of the component after an <code>await</code> operation on a <code>Task</code>. It can be easily tested by putting in commentary the <code>result =  await _LogInService.TryLogIn(logInForm);</code> line or changing <code>IsDisabled = ...</code> to <code>await new Task.Run(() =&gt; { IsDisabled = ...})</code>. I have some workaround now, but I still wonder why this is a feature. Shouldn't <code>StateHasChanged()</code> re-render after any operations ? Or it consider that only <code>async</code> operations (so mostly server-calls) can change something in the UI ?</p>