using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace TestTestTest { class Program { static void Main(string[] args) { var list = new SortedList(); foreach (var name in Directory.GetFiles("C:\\WINDOWS")) { list.Add(name, new FileInfo(name)); } Action a = () => { while (true) { foreach (var kvp in list) { Console.WriteLine("Action=A:{0}", kvp.Value.Name); } } }; Action b = () => { while (true) { for (int i = 0; i < list.Count; i++) { Console.WriteLine("Action=B:{0}", list[list.Keys[i]].Name); } } }; for (int i = 0; i < 25; i++ ) { Task.Factory.StartNew(a); Task.Factory.StartNew(b); } Thread.Sleep(600 * 1000); } } }