Hi. I need to remove items from list few seconds after i added them. I have now an ObservableCollection to which I add some messages. I need them to be deleted let's say 5 seconds after they were added. I tried to create a function responsible for adding the items and setting a timer:
public void AddInfoItem(string info)
{
infoList.Add(info);
Timer newTimer = new Timer(5000);
newTimer.Elapsed += new ElapsedEventHandler(this.TimerFunction);
newTimer.Enabled = true;
newTimer.Start();
}
public void TimerFunction(Object sender, EventArgs e)
{
infoList.Clear();
}
I didn't even send any parameters which item should be removed cause the second function raised an exception. Can somebody describe a proper solution to add item and delete it after some time?
Sory for not writing it earlier. The exception is
this type of collectionview does not support changes to its sourcecollection from a thread different from the dispatecher thread