public void Enqueue(string source, string message, long time, long duration, int eventType) { Interlocked.Increment(ref _postedMessages); while (true) { LogBuffer buf = _last; if (!buf.PushMessage(source, message, time, duration, eventType)) { lock (lck) { if (!buf.Done) { continue; } LogBuffer nb = new LogBuffer(); if (Interlocked.CompareExchange(ref _last, nb, buf) == buf) { buf.Next = nb; } } } else { break; } } }