title: Blazor question- close circuit\connection immediately after making async call
body: <p>I have a blazor integration and basically, after an indeterminate period of time I see this screen: </p>
  
  <p><a href="https://i.stack.imgur.com/G3U6e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G3U6e.png" alt="enter image description here"></a></p>
  
  <p>Is there no way to prevent this from happening?  My concern is that I'm maybe not closing circuits/connections after I have the data I need from the server-side call.  </p>
  
  <p>I have this in my ComponentBase class: </p>
  
  <pre><code>  protected override async Task OnInitializedAsync()
      {
           await DoStuff();
      }
  </code></pre>
  
  <p>which calls to this: </p>
  
  <pre><code> private async Task DoStuff()
      {
  
          var results= await httpClient.GetJsonAsync&lt;MyResultsClass&gt;(someResultsUrl);
            ...  
          StateHasChanged();
      }
  </code></pre>
  
  <p>But I'm wondering if I need something after the fact (maybe need to implement IDisposable, have some kind of a handle to any created circuits, and dispose of it immediately) to make sure that it gets automatically cleaned up?  That message should never show, and there is no need to keep any kind of connection open after I get the results I need.  I just don't know what sort of handler\object I need that represents the Blazorconnection that is being made. </p>
  
  <p>I found <a href="https://stackoverflow.com/questions/61345537/detect-client-closing-connection-blazor">this</a> link but it seems like a lot to accomplish one little thing.  </p>
  
  <p><strong>Edit</strong>: after trying the proposed solution, I'm seeing slightly different behavior involving a message saying "Attempting to reconnect to server".  When that doesn't work, I see "Could not reconnect to the server.  Reload the page to restore functionality".  Is there no way to automate this, or, at least, prevent it completely by automatically closing the connection\circuit (if it isn't needed)?  </p>
  
  <p><strong>Edit 2</strong>: it would also be suitable if the reconnection happened automatically, if\where possible - if I leave my blazor page open for a long time, reconnection doesn't seem to work.  But, if it were to reconnect at the moment it lost connection, I presume that it could help?  </p>
  
  <p><strong>Edit 3</strong>: other alternative I'd be happy with is if the page automatically refreshed <em>instead</em> of a reconnection - that would work for me just fine.  </p>
  
  <p><strong>Edit 4</strong>: (in response to <a href="https://stackoverflow.com/a/62281431/624071">enet's answer</a>) - helps a lot, thanks!  And I agree, it's a hack to try to forcibly close the connection.  I was just hoping there was a way to gracefully close the connection, knowing that once DoStuff() is done doing what it needs to do, it can release the resources - instead of unnecessarily lingering.  If this is a consequence of Blazor that I have to live with, then it's fine.  I've found a way to suppress the "Hateful screen" (as you call it) that comes up which is great, but would be nice if I could clean up the "Error: Connection disconnected with error "Error: WebSocket closed with status code: 1006 ().'  I've seen a lot of threads about that error, and they mostly lean to the solution of force an automatic refresh.  I don't actually care if the error even happens, I just want to make sure that it will eventually free up the resources (and if it happens automatically, then I'm fine with that, too.)  - would ideally like to be able to catch\ignore that error message, but if it's something I should be concerned about, then...  I don't want to ignore it.  Also, this issue is very easy to reproduce and I don't have to recycle my website app pool or anything like that. </p>