public override void Work() { while (true) { Block_byte tmp = new Block_byte(); tmp.block = new byte[blockSize]; lock (locker1) { while (block_compress_keys.Count == 0 && isRead) { Monitor.Wait(locker1); } if (block_compress_keys.Count == 0 && !isRead) { break; } tmp = block_compress_keys.Dequeue(); } byte[] buf = new byte[tmp.length]; using (MemoryStream source = new MemoryStream(tmp.block)) { using (GZipStream gzip = new GZipStream(source, CompressionMode.Decompress)) { gzip.Read(buf, 0, buf.Length); lock (locker2) { block_send_keys.Add(tmp.position, new Block_byte() { block = buf, length = buf.Length }); Monitor.Pulse(locker2); } } } long mem = GC.GetTotalMemory(true); if (mem > memoryPeak) { memoryPeak = mem; } } lock (locker2) { if (--workingThreads == 0) { isWork = false; Monitor.PulseAll(locker2); } } }
public override void Work() { while (true) { int count; lock (locker1) { count = block_send_keys.Count; } if (count <= processorCount) { using (MemoryStream memory = new MemoryStream()) { Block_byte tmp = new Block_byte(); using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress)) { tmp.block = new byte[blockSize]; lock (locker1) { while (block_compress_keys.Count == 0 && isRead) { Monitor.Wait(locker1); } if (block_compress_keys.Count == 0 && !isRead) { break; } tmp = block_compress_keys.Dequeue(); } gzip.Write(tmp.block, 0, tmp.length); } byte[] buf = memory.ToArray(); lock (locker2) { block_send_keys.Add(tmp.position, new Block_byte() { block = buf, length = buf.Length }); Monitor.Pulse(locker2); } } } long mem = GC.GetTotalMemory(true); if (mem > memoryPeak) { memoryPeak = mem; } } lock (locker2) { if (--workingThreads == 0) { isWork = false; Monitor.PulseAll(locker2); } } }