I'm building a sample project using SignalR. The idea is that i have 3 different screens that shows a video, every 4 seconds the screen randomly changes and save the screen ID, the video ID and the timestamp as an object in a IEnumerable list. I want the list to store only the last 10 changes, so if a new change is stored in the first position, the oldest element needs to be removed; since there are multiple screens changing the list the elimination method can't be limited to delete the last element of the list, 2 screens could add something to the list at the same time and the list would be 12+ changes size.
How can i delete all the elements of the list that excedes the 10 changes limit?
This is the code related to the list.
private readonly ConcurrentDictionary<string, Cambio> _cambios = new
ConcurrentDictionary<string, Cambio>();
var cambios = new List<Cambio>
{
new Cambio{pantalla = "Sin cambios", video= "Sin cambios",
tStamp = DateTime.Now}
//Sample
};
cambios.ForEach(cambio =>
_cambios.TryAdd(cambio.tStamp.ToString(), cambio));
public class Cambio
{
public string pantalla { get;set;}
public string video { get; set; }
public DateTime tStamp { get; set; }
}