/// <summary> /// Cleans up any resources being used. /// </summary> public void Dispose() { if (m_IsDisposed) { return; } m_IsDisposed = true; // Release events. this.BufferFull = null; try{ // If recording, we need to reset wav device first. WavMethods.waveInReset(m_pWavDevHandle); // If there are unprepared wav headers, we need to unprepare these. foreach (BufferItem item in m_pBuffers) { WavMethods.waveInUnprepareHeader(m_pWavDevHandle, item.HeaderHandle.AddrOfPinnedObject(), Marshal.SizeOf(item.Header)); item.Dispose(); } // Close input device. WavMethods.waveInClose(m_pWavDevHandle); m_pInDevice = null; m_pWavDevHandle = IntPtr.Zero; } catch { } }
protected virtual void Dispose(bool disposing) { if (!m_IsDisposed) { // Release events. this.BufferFull = null; try { // If recording, we need to reset wav device first. WavMethods.waveInReset(m_pWavDevHandle); // If there are unprepared wav headers, we need to unprepare these. lock (m_pBuffers) { foreach (BufferItem item in m_pBuffers) { try { WavMethods.waveInUnprepareHeader(m_pWavDevHandle, item.HeaderHandle.AddrOfPinnedObject(), Marshal.SizeOf(item.Header)); } catch { Debug.WriteLine("WaveIn.Dispose() - WavMethods.waveInUnprepareHeader()"); } item.Dispose(); } } // Close input device. Debug.WriteLine("WaveIn.Dispose() - waveInClose"); try { WavMethods.waveInClose(m_pWavDevHandle); } catch { Debug.WriteLine("WaveIn.Dispose() - WavMethods.waveInClose()"); } finally { m_pInDevice = null; m_pWavDevHandle = IntPtr.Zero; } } catch (Exception ex) { Debug.WriteLine("WaveIn.Dispose() - " + ex.Message); } } m_IsDisposed = true; }