From what I understand, a SimEvents simulation is being run, and some entities haven't reached the terminal state by the end of the simulation.
A straightforward way to handle dynamic termination is to set the simulation's Stop Time to 'inf' (or a very high value) and use the Stop Simulation block to end the simulation when needed.
The attached file example_R2021b.slx includes the following model.
In this setup, the Gen_5s block generates entities for the first 5 seconds at a rate of 10 entities per second. The Entity Server has a capacity limit of 6, so some entities don't reach the terminal state if Stop Time is set to 10 seconds.
Instead, the Stop Time is set as ‘inf’ and a condition is used to monitor when the number of entities in the server reaches 0, using the Compare to Zero block. The resulting boolean signal triggers the Stop Simulation block, which then terminates the simulation.
For more details on the Stop Simulation block, check out this documentation page:
I believe this will assist you!