Ejemplo n.º 1
0
        public void TestCachingDictionaryClear()
        {
            Random random = new Random();
            CachingDictionary <int, Guid> cache = new CachingDictionary <int, Guid>();

            // Build cache in parallel
            Parallel.For(
                0,
                CacheSize,
                i => cache.AddOrUpdate(i, Guid.NewGuid(), DateTime.Now.AddMilliseconds(random.Next(1000, 60000))));

            Parallel.Invoke(
                () =>
            {
                int count = 0;
// ReSharper disable LoopCanBeConvertedToQuery
                foreach (Guid guid in cache.Values)
                {
// ReSharper restore LoopCanBeConvertedToQuery
                    count++;
                }
                Trace.WriteLine(string.Format("Count was {0}", count));
            },
                cache.Clear);

            Trace.WriteLine(cache.ToString());
        }