public void DoWork() { while (true) { ewhStart.WaitOne(); if (m_Command == 0) // encode { Huffman.Encode(ref m_aIn, out m_aOut); } else if (m_Command == 1) // decode { Huffman.Decode(ref m_aIn, out m_aOut); } else { ewhStop.Set(); break; } ewhStop.Set(); } }
public void Decode(ref byte[] pBufIn, out byte[] pBufOut) { int i; pBufOut = null; if (pBufIn[0] == 0) { byte[] aIn = new byte[pBufIn.Length - 1]; Array.Copy(pBufOut, 1, aIn, 0, aIn.Length); Huffman.Decode(ref aIn, out pBufOut); return; } // === start threads === Start(); // ===================== int j; int StartIndex = 1; for (i = 0; i < m_ProcessCount; i++) { int size = BitConverter.ToInt32(pBufIn, StartIndex); StartIndex += sizeof(int); byte[] aIn = new byte[size]; Array.Copy(pBufIn, StartIndex, aIn, 0, aIn.Length); StartIndex += size; m_threadRoutine[i].ArrayIn = aIn; } for (i = 0; i < m_ProcessCount; i++) { m_threadRoutine[i].m_Command = 1; m_threadRoutine[i].ewhStart.Set(); } int outSize = 0; for (i = 0; i < m_ProcessCount; i++) { m_threadRoutine[i].ewhStop.WaitOne(); outSize += m_threadRoutine[i].ArrayOut.Length; } pBufOut = new byte[outSize]; StartIndex = 0; for (i = 0; i < m_ProcessCount; i++) { byte[] aOut = m_threadRoutine[i].ArrayOut; Array.Copy(aOut, 0, pBufOut, StartIndex, aOut.Length); StartIndex += aOut.Length; } // === stop threads === Stop(); // ==================== }