title: Program hangs up when using NAudio record sound and save
body: <p>I encountered some problems in using NAudio to save sound recordings. Most of time, the following code will work. It will start recording and saving to .wav file after I press the "start recording" button, and stops recording after I press the "stop" button. But sometimes, the program just hangs up after I click the recording button. I have to wait around 30 seconds before it starts recording properly.  </p>
  
  <pre><code>    private WaveIn waveSource = null;
      private WaveFileWriter waveFile = null;
  
      private void recordButton_Click(object sender, EventArgs e)
      {
          recordButton.Enabled = false;
          stopRecordButton.Enabled = true;
          waveSource = new WaveIn();
          waveSource.WaveFormat = new WaveFormat(44100, 1);
          waveSource.DataAvailable += new EventHandler&lt;WaveInEventArgs&gt;(waveSource_DataAvailable);
          waveSource.RecordingStopped += new EventHandler&lt;StoppedEventArgs&gt;(waveSouce_RecordingStopped);
  
          waveFile = new WaveFileWriter("test.wav", waveSource.WaveFormat);
          waveSource.StartRecording();
      }
  
      private void stopRecordButton_Click(object sender, EventArgs e)
      {
          stopRecordButton.Enabled = false;
          waveSource.StopRecording();
      }     
  
      private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
      {
          if (waveFile != null)
          {
              waveFile.Write(e.Buffer, 0, e.BytesRecorded);
              waveFile.Flush();
          }
      }
  
      private void waveSouce_RecordingStopped(object sender, StoppedEventArgs e)
      {
          DisposeWave();
      }
  
      private void DisposeWave()
      {
          if (waveSource != null)
          {
              waveSource.Dispose();
              waveSource = null;
          }
          if (waveFile != null)
          {
              waveFile.Dispose();
              waveFile = null;
          }
      }
  </code></pre>
  
  <p>I set a break in visual studio, and found it hangs on line: waveSource.StartRecording(); 
  It takes around 30 seconds to step into function: private void waveSource_DataAvailable(). </p>
  
  <p>I also ran this program on another computer, but I get the following exception text after I click the "start recording" button. I checked the Device Manager on that computer, and I'm pretty sure the sound card is properly installed. </p>
  
  <pre><code>************** Exception Text **************
  NAudio.MmException: BadDeviceId calling waveInOpen
    at NAudio.Wave.WaveIn.OpenWaveInDevice()
    at NAudio.Wave.WaveIn.StartRecording()
    at ToeflSpeaking.MainForm.StartRecordingState() in c:\MyProgram\Toefl Speaking\code\MainForm.cs:line 268
    at ToeflSpeaking.MainForm.timer_Tick(Object sender, EventArgs e) in c:\MyProgram\Toefl Speaking\code\MainForm.cs:line 407
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message&amp; m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  </code></pre>