using System.Threading.Tasks;
using System.Collections.Concurrent;
public static void Main()
var widgetBag = new ConcurrentBag<Widget>();
Parallel.For(0, 100000, (i) => {
var dupes = widgetBag.GroupBy(w => w.ID)
.Where(g => g.Count() > 1)
Console.WriteLine("Bad news - duplicates exist, count is: " + dupes.Count());
private static int _NextId;
private readonly object _LockToken = new object();
public int ID { get; private set; }