I have an ASP.NET MVC application and I am using server-sent events. The application works fine but I am having some questions on how it works. Below is the controller code.
The time gets updated only every 3 seconds. Why is it so?
Because your Controller
is returning the ActionResult
containing a single data and then closing the connection, so the browser waits 3 seconds and then re-opens it.
How to determine how often the controller action will be called?
The same way you would determine how often any other method will be called, with loops and delays.
SSE is Server Sent Events, you manage all this stuff from the server side, it'll only work properly if you explicitly hold the connection open, otherwise you may as well do AJAX polling from the client instead.