public Int32 GetCRC(Stream stream) { UInt32 crcCurrent = CRC32InitValue; byte[][] buf = new byte[2][]; buf[0] = new byte[TotalBufferSize]; buf[1] = new byte[TotalBufferSize]; UInt32[] bufferCRC = new UInt32[NumberOfBuffers]; int count; object state = new object(); int bufCurrent = 0; IAsyncResult result = stream.BeginRead(buf[bufCurrent], 0, TotalBufferSize, null, state); count = stream.EndRead(result); while (count != 0) { if (count < TotalBufferSize) { crcCurrent = HashBlock16(crcCurrent, buf[bufCurrent], 0, count); break; } result = stream.BeginRead(buf[(bufCurrent + 1) & 0x1], 0, TotalBufferSize, null, state); GetBufferCRC(bufferCRC, buf[bufCurrent]); crcCurrent = MergeCRCs(crcCurrent, bufferCRC); bufCurrent = (bufCurrent + 1) & 0x1; count = stream.EndRead(result); } return unchecked((Int32)~crcCurrent); }