locked
Windows store app - Timed operations RRS feed

  • Question

  • I have a list of of stringsDouble called Messages.

    The code for the class is below:

    public class stringsDouble {

    public string Sender{get;set;}

    public string message{get;Set;} public DateTime time{get;Set;} }


    every time my app receives a new message. I update the List and i store the time of the latest message sent for the user sending that message.

    what i want to do is, every 5 minutes the app should go through the list. 

    and for every item in the list it should get the time property and get the current system time , and check to see if the difference is more than 30 minutes. If it is, it should delete that item from the list.

    How can i accomplish this?

    Monday, December 30, 2013 6:35 AM

Answers

  • something like this?

    DispatcherTimer _timer;
            ObservableCollection<stringsDouble> _list = new ObservableCollection<stringsDouble>();
            public GroupedItemsPage()
            {
                _timer = new DispatcherTimer();
                _timer.Interval = TimeSpan.FromMinutes(5);
                _timer.Tick += _timer_Tick;
                _timer.Start();
            }
    
            void _timer_Tick(object sender, object e)
            {
                var thressHold = DateTime.Now.Subtract(TimeSpan.FromMinutes(30));
                var itemsToRemove = _list.Where(x => x.time < thressHold).ToArray();
                foreach(var item in itemsToRemove)
                    _list.Remove(item);
            }

    you can databind the list to that observablecollection.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by kalel111 Tuesday, December 31, 2013 1:44 AM
    Monday, December 30, 2013 9:42 AM