using System.Collections.Concurrent;
static ConcurrentDictionary<int, string> _concurrent = new ConcurrentDictionary<int, string>();
Thread thread1 = new Thread(() => A("1",2));
Thread thread2 = new Thread(() => A("2",3));
Console.WriteLine("Total: {0}", _concurrent.Count());
Console.WriteLine("--------------------");
_concurrent.TryAdd(1, "Teste");
foreach(var item in _concurrent)
Console.WriteLine("Key: {0} | Value: {1}", item.Key, item.Value);
Console.WriteLine("Sucesso: {0}", _concurrent.TryAdd(31, "Teste"));
Console.WriteLine("Sucesso: {0}", _concurrent.TryAdd(31, "Teste"));
static void A(string val, int n)
for (int i = 1; i < 11; i++)
_concurrent.TryAdd(i * n, i.ToString() + " " + val);
Thread.Sleep(TimeSpan.FromMilliseconds(100));