Answer the question
In order to leave comments, you need to log in
How to build a .NET application with a large number of cycling elements?
Good afternoon.
I am making a small toy on dotNet, it contains the same type of elements (portals). Each portal lives in an activation / deactivation cycle, each has its own life / downtime. When activated / deactivated, some event occurs. What architecture to use for the system?
Cling to the timer with hundreds of portals and check on every tick if it's time to switch any elements?
Create a method that causes a status change after n seconds, and call it on a new thread at the end of itself?
Create a time-sorted list of pending changes, and check on every tick of the timer if it's time to change the first portal?
The number of portals is approximately no more than 1000.
Answer the question
In order to leave comments, you need to log in
create a portal class, in the class when it is created, launch a task or thread in which there will be a Thread.Sleep in accordance with the cycles after activation, you can use event or perform processing inside the object by tasks. With this approach, it will easily pull in hundreds of thousands, not to mention a thousand.
RX
has an excellent set of classes with a common IScheduler interface that allow you to schedule tasks for execution at the right time and at the right interval. In your case, TaskPoolScheduler will do.
But in general, games often use the usual loop approach, in which the next game frame is processed. At each iteration, the game time is determined, and events are processed based on it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question