using System.Threading.Tasks;
public static void Main()
this.fixErrorLock = new object();
var objectsToIterate = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
objectsToIterate.AsParallel().ForAll(this.DoWork);
private object fixErrorLock;
public void DoWork(int myParam)
this.PrintThreadMessage("Waiting to check if the problem have to be solved.");
this.FixTheProblem(ref myParam);
this.PrintThreadMessage("Problem solved!");
public void FixTheProblem(ref int param)
this.PrintThreadMessage("Solving the problem...");
private void PrintThreadMessage(string message)
Console.WriteLine(string.Format("{0} (Thread id: {1})", message , Thread.CurrentThread.ManagedThreadId));