Revision 7f5882da trunk/Pithos.Core/TaskExtensions.cs

b/trunk/Pithos.Core/TaskExtensions.cs
157 157

  
158 158
        public static bool TryRemove<T>(this ObservableConcurrentCollection<T> collection,T item) where T:class
159 159
        {
160
            var found = false;
160 161
            IProducerConsumerCollection<T> items= collection;
161
            for (var i = 0; i < items.Count; i++)
162
            //Store the initial count
163
            var count = items.Count;
164
            for (var i = 0; i < count; i++)
162 165
            {
163 166
                T tempItem;
167
                //Take an item
164 168
                if (!items.TryTake(out tempItem)) 
165 169
                    return false;
166
                if (tempItem == item) 
167
                    return true;
168
                items.TryAdd(item);
170
                //If it isn't the one we are looking for
171
                if (tempItem != item)
172
                    //put it back
173
                    items.TryAdd(tempItem);
174
                else
175
                    //otherwise skip it and flag succcess
176
                    found = true;
169 177
            }
170
            return false;
178
            return found;
171 179
        }
172 180

  
173 181
        public static bool TryAdd<T>(this ObservableConcurrentCollection<T> collection,T item) where T:class

Also available in: Unified diff