CSharp · Console
using System.Collections.Concurrent;
using System.Threading;
namespace Samples.Console
{
public class Program
{
public static void Main(string[] args)
{
Thread thread1 = new Thread(() => StaticField.StaticFieldTest());
Thread thread2 = new Thread(() => StaticField.StaticFieldTest());
thread1.Start();
thread2.Start();
Thread.Sleep(1000);
}
public class StaticField
{
public static readonly ConcurrentDictionary<string, string> _dic = InitDictionary();
public static void StaticFieldTest()
{
System.Console.WriteLine("Start Running...");
_dic.TryAdd(string.Empty, string.Empty);
_dic.TryAdd(string.Empty, string.Empty);
_dic.TryAdd(string.Empty, string.Empty);
}
public static ConcurrentDictionary<string, string> InitDictionary()
{
System.Console.WriteLine("The Dictionary has been initialized now");
Thread.Sleep(500);
return new ConcurrentDictionary<string, string>();
}
}
}
}