// ReSharper disable once UnusedParameter.Local
        private TestThread CreateInsertThread(int mainCounter, ManualResetEvent signal)
        {
            var tt = TestThread.Start(th =>
            {
                for (int i = 0; i < 10; i++)
                {
                    _dict.TryAdd("" + i, "" + i);
                    _added++;
                }
                return(true);
            }, signal);

            return(tt);
        }
Exemplo n.º 2
0
 public static void AddMonitor(string id, BaseMetric metric)
 {
     if (!_started)
     {
         if (!_beforeStart.ContainsKey(id))
         {
             _beforeStart.Add(id, metric);
         }
     }
     else
     {
         metric.Initialize(_periodRun, id.ToLowerInvariant());
         _perfData.TryAdd(id.ToLowerInvariant(), metric);
     }
 }
Exemplo n.º 3
0
        public void LockFreeDictionaryTryAddKeyValuePair()
        {
            var dict = new AsyncLockFreeDictionary <int, int>();

            Thread.Sleep(100);
            dict.Add(1, 1);
            dict.Add(2, 2);
            Thread.Sleep(100);
            dict.TryAdd(new KeyValuePair <int, int>(1, 100), (preExisting, newKeyValuePair) => new KeyValuePair <int, int>(newKeyValuePair.Key, newKeyValuePair.Value * 2));
            Thread.Sleep(100);

            Assert.AreEqual(2, dict.Count);
            Assert.AreEqual(200, dict[1]);
            Assert.AreEqual(2, dict[2]);
        }