public void PeekMessages(object prm) { PeekThreadParam p = prm as PeekThreadParam; string qName = p.MsmqQueue.GetDisplayName(); uint sameCount = 0; string lastId = string.Empty; bool _isPeeking = false; SetupMessageReadPropertyFilters(p.MsmqQueue, p.Queue.Type); p.MsmqQueue.PeekCompleted += (source, asyncResult) => { if (_monitorState.IsMonitoring(p.Queue.Type)) { Message msg = p.MsmqQueue.EndPeek(asyncResult.AsyncResult); if (msg.Id == lastId) { sameCount++; } else { sameCount = 0; TryAddItem(msg, p.Queue); } if (lastId != msg.Id) { lastId = msg.Id; } } _isPeeking = false; }; while (!_terminated) { while (!_monitorState.IsMonitoring(p.Queue.Type)) { Thread.Sleep(1000); if (_terminated) { return; } } if (!_isPeeking) { if (sameCount > 0) { if (sameCount / 10.0F == 1.0F) { Thread.Sleep(100); } else if (sameCount / 100.0F == 1.0F) { Thread.Sleep(200); } else if (sameCount % 300 == 0) { Thread.Sleep(500); } } p.MsmqQueue.BeginPeek(); _isPeeking = true; } Thread.Sleep(100); } }