private async void IterateItemSetAndRepeat(IServiceCallback callback) { string currentItem = String.Empty; while (true) { //Determine which item is next to be polled lock (lock_itemSet) { //This will get the next element in the set (alphabetical by Name), assuming there is one to get... ItemInfo nextModel = m_ItemsToTrack.FirstOrDefault(model => String.Compare(model.Name, currentItem) > 0); //...otherwise, circle back to the first item... if (nextModel == null) { nextModel = m_ItemsToTrack.FirstOrDefault(); } currentItem = nextModel != null ? nextModel.Name : String.Empty; } if (currentItem != String.Empty) { ItemInfo updatedModel = null; //Determine if cache contains "fresh" item info update // This is where we would query the DB for 'time_of_last_update' // Was it within the (TBD) time period // //if (cacheContainsFreshData) //{ // models[currentItem] = ... //query db, fill model //} //else try { updatedModel = await PollDataSource(currentItem); } catch { try { callback.ClientErrorMessage("This is an error message! >8-P <3 :) meh"); } catch { } } if (updatedModel != null) { //Update memento lock (lock_itemSet) { m_ItemsToTrack.RemoveWhere(item => item.Name.Equals(currentItem)); m_ItemsToTrack.Add(updatedModel); } //Push updated model to client XmlSerializer xmlSerializer = new XmlSerializer(updatedModel.GetType()); MemoryStream itemInfoStream = new MemoryStream(); xmlSerializer.Serialize(itemInfoStream, updatedModel); try { callback.ClientUpdate(itemInfoStream); } catch (TimeoutException) { //shutdown session? } } Thread.Sleep(m_DelayBetweenPollsInMS); } else { Thread.Sleep(1000); } } }