In a blazor server application, is it okay to send events and call StateHasChanged
very often, e.g., 500 times per second?
One of my pages needs to react to an external event and then update its state accordingly. I found the following solution:
- Create a service that detects the external event and invokes a C# event.
- Inject the service into the razor page.
- In the page, connect to the event and call
InvokeAsync(() => StateHasChanged())
in the handler.
This already works correctly. However, the event may occur very often, e.g., 500 times per second, and I worry about the performance of client and server. Unfortunately, I dont understand which part happens on the server, which part happens on the client, and which data is sent between them.
- Are the events actually sent 500 times per second from the server to the client? I think this would consume a lot of bandwidth.
- Does the client actually render the page after each call to
StateHasChanged
? I think this would impose a high CPU load on the client.