public void ExecuteWithOwnInstances() { Task[] tasks = new Task[10]; for (int i = 0; i < 10; i++) { tasks[i] = Task.Run(() => { var test = new WhatIsShared_17(); Console.WriteLine(test.GetLocal()); Console.WriteLine(test.GetInstanceLevel()); Console.WriteLine(test.GetStaticLevel()); }); } Task.WaitAll(tasks); }
public void ExecuteWithThreads() { var test = new WhatIsShared_17(); Thread[] threads = new Thread[10]; for (int i = 0; i < 10; i++) { threads[i] = new Thread(() => { Console.WriteLine(test.GetLocal()); Console.WriteLine(test.GetInstanceLevel()); Console.WriteLine(test.GetStaticLevel()); }); threads[i].Start(); } foreach (var t in threads) { t.Join(); } }