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.
I wouldn't increment things inside a parallel foreach (unless, of course, you're using Interlocked.Increment or some other locking mechanism). That's not what it's for. The Parallel foreach should be run only with actions that cause no side effects in shared state. To increment a value in a parallel foreach will cause the very problem you're more than likely trying to avoid.