Is it safe to dispose WaveIn
and WaveOut
right after stopping them, and not in the event handlers of WaveIn.RecordingStopped
and WaveOut.PlaybackStopped
? Like this:
MyWaveIn.StopRecording();
MyWaveIn.Dispose();
MyWaveIn = null;
And:
MyWaveOut.Stop();
MyWaveOut.Dispose();
MyWaveOut = null;
If WaveIn
/ WaveOut
stopped due to an error, or if the playback stopped because the file being played reach its end, I will dispose them in the event handlers. I'm asking just about the situation where I stop them explicitly.
I generally recommend disposing in the PlaybackStopped
event handler, but most soundcard drivers seem perfectly happy with you disposing while playback or recording is still in progress (under the hood you're just calling the waveOutClose
or waveInClose
windows API).