Click here to Skip to main content
15,895,084 members
Articles / Programming Languages / C#

Asynchronous Multi-threaded ObservableCollection

Rate me:
Please Sign up or sign in to vote.
4.85/5 (18 votes)
9 May 2014CPOL6 min read 124.8K   4.4K   112  
An implementation of of a multi-threaded ObservableCollection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HQ.Util.General.Collections
{
    public static class CollectionExtension
    {
        // ******************************************************************
        public static ICollection<T> RemoveAll<T>(this ICollection<T> coll, Func<T, bool> condition)
        {
            var itemsToRemove = coll.Where(condition).ToList();

            foreach (var itemToRemove in itemsToRemove)
            {
                coll.Remove(itemToRemove);
            }

            return coll;
        }

        // ******************************************************************
        public static ICollection<T> RemoveAll<T>(this ICollection<T> coll)
        {
            RemoveAll(coll, (x) => true);
            return coll;
        }

        // ******************************************************************
        public static void AddMany<T>(this ICollection<T> coll, IEnumerable<T> enumT)
        {
            foreach(T t in enumT)
            {
                coll.Add(t);
            }
        }

        // ******************************************************************

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer IREQ - Hydro-Quebec
Canada Canada
Hi,

I'm a french Canadian software developer.
Work at Hydro-Quebec / IREQ.
Live in Sainte-Julie, Quebec, Canada (South shore of Montreal)

WebPage: http://www.ericouellet.com
GMail: ericouellet2

Salut!

Comments and Discussions