I want a list that would hold a item for a specified time.
This is what I tried for now:
private void digtimer_Tick(object sender, EventArgs e) //Goes off every half a second
{
justmine.Clear();
}
However, this way deletes all of the items after every interval, regardless of how long the items in the list existed. Is there any way so that after an list item exists for a specified time, it is removed?
EDIT: The list is integers only. The newest code is:
` //public static Dictionary<int, DateTime> justmine = new Dictionary<int, DateTime>();
//Adding an item is: justmine.Add(userid, DateTime.Now);
private void digtimer_Tick(object sender, EventArgs e)
{
foreach (KeyValuePair<int, DateTime> pair in justmine)
{
console.Items.Add((DateTime.Now - pair.Value).TotalSeconds).ToString();
string x = ((DateTime.Now - pair.Value).TotalSeconds).ToString();
if ((Convert.ToDouble(x) < 500.0))
{
justmine.Remove(pair.Key);
}
}
}
`
This would of seemed to work, but I am not able to edit the dictionary while the tick is running. EXTRA NOTE This list is now a Dictionary with
public static Dictionary<int, DateTime> justmine = new Dictionary<int, DateTime>();