0

I'm learning Blazor and I want to create a method that works like a countdown. This part I have already done. However, I would like to know if it is possible to run the same (initial) instance of this method on all clients, so regardless when clients open the website, they will have the same countdown value. How can I achieve that? Thank you for any help.

GoodOldGuy
  • 172
  • 4
  • 8

1 Answers1

3

You need to use a singleton service for this, and in the service your countdown is taking place. The countdown will need to be on a server and if you are using Server Side Blazor, the set up is fairly simple.

Review my answer in this post for an outline on how to set up the service, and there is also a link in that post to a GitHub project that has a working demo of the service passing information out to clients. The adaptation for your countdown would be pretty simple.

If you are looking to do this in client side blazor, it becomes a bit more complex. You will still need a server somewhere to synchronize the countdown, but connections could be done using SignalR, a gRPC stream, or other technologies of your choosing.

Nik P
  • 2,693
  • 9
  • 21