private void BackgroundThread() { while (!_backgroundThreadStop) { bool shouldSleep = true; lock (_queueLock) { if (_packetQueue.Count != 0) { shouldSleep = false; } } if (shouldSleep) { System.Threading.Thread.Sleep(250); } else { List <RawCapture> ourQueue; lock (_queueLock) { ourQueue = _packetQueue; _packetQueue = new List <RawCapture>(); } //Console.WriteLine("BackgroundThread: ourQueue.Count is {0}", ourQueue.Count); foreach (RawCapture rawCapture in ourQueue) { // NOTE: If the incoming packet rate is greater than // the packet processing rate these queues will grow // to enormous sizes. Packets should be dropped in these // cases if (_bEveryPacket) { PacketWrapper2 pw = new PacketWrapper2(rawCapture); BeginInvoke(new MethodInvoker(delegate { bs.Add(pw); })); } else { _tcpRecon.ReassemblePacket(rawCapture); } } if (_statisticsUiNeedsUpdate) { UpdateCaptureStatistics(); _statisticsUiNeedsUpdate = false; } } } }
private void BackgroundThread() { while (!_backgroundThreadStop) { bool shouldSleep = true; lock (_queueLock) { if (_packetQueue.Count != 0) shouldSleep = false; } if (shouldSleep) System.Threading.Thread.Sleep(250); else { List<RawCapture> ourQueue; lock (_queueLock) { ourQueue = _packetQueue; _packetQueue = new List<RawCapture>(); } //Console.WriteLine("BackgroundThread: ourQueue.Count is {0}", ourQueue.Count); foreach (RawCapture rawCapture in ourQueue) { // NOTE: If the incoming packet rate is greater than // the packet processing rate these queues will grow // to enormous sizes. Packets should be dropped in these // cases if (_bEveryPacket) { PacketWrapper2 pw = new PacketWrapper2(rawCapture); BeginInvoke(new MethodInvoker(delegate { bs.Add(pw); })); } else _tcpRecon.ReassemblePacket(rawCapture); } if (_statisticsUiNeedsUpdate) { UpdateCaptureStatistics(); _statisticsUiNeedsUpdate = false; } } } }