private void UpdateWithSpinLock(Data31 d, int i) { bool lockTaken = false; try { _spinlock.Enter(ref lockTaken); if (!_queue.Contains(d)) { Thread.Sleep(250); _queue.Enqueue(d); } else { Console.WriteLine("Already exists: {0}", d); } } finally { if (lockTaken) { _spinlock.Exit(); } } }
private void UpdateWithLock(Data31 d, int i) { bool lockTaken = false; try { Monitor.Enter(_lock, ref lockTaken); _queue.Enqueue(d); } finally { if (lockTaken) { Monitor.Exit(_lock); } } }