public static void TestThreadProptery() { TestThreadProptery_Data data = new TestThreadProptery_Data(); s_startTime = Stopwatch.GetTimestamp(); ThreadPool.QueueUserWorkItem(o => TestThreadProptery_AccessData(data, 0)); ThreadPool.QueueUserWorkItem(o => TestThreadProptery_AccessData(data, 1)); }
public static void TestThreadProptery_AccessData(TestThreadProptery_Data data, int field) { for (int x = 0; x < iterations; x++) { if (field == 0) { data.field1++; } else { data.field2++; } } if (Interlocked.Decrement(ref s_operations) == 0) { Console.WriteLine("access time :{0}", (Stopwatch.GetTimestamp() - s_startTime) / Stopwatch.Frequency / 1000.00); } }