public void ThreadRun() { try { m_stream.Start(Convert.ToInt32(wavDataProvider.SampleRate)); int nSamples = Convert.ToInt32(wavDataProvider.SampleRate / 50); do { System.Runtime.InteropServices.ComTypes.IStream strm = wavDataProvider.GetNextAudioChunk(nSamples); if (null == strm) { break; } while (false == PushSamples(strm)) { Thread.Sleep(20); } System.Runtime.InteropServices.Marshal.FinalReleaseComObject(strm); strm = null; } while (wavDataProvider.HasMoreData); } catch (COMException) { } m_stream.Stop(); AllDataWritten.Invoke(this, null); }