How can I increment an integer value outside the scope of a parallel.foreach loop? What\'s is the lightest way to synchronize access to objects outside parallel loops?
Use Interlocked.Increment method in this way.
int count = 0; Parallel.ForEach(users, (u) => { var currentCount = Interlocked.Increment(ref count); Log(String.Format("Step {0} of {1}", currentCount, users.Count)); });