There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
WasapiCapture class - deadlock in StopRecording()
Deadlock has place in StopRecording() in WasapiCapture class in the implementation presented in WavRecording demo code.
When Stop button is pressed then StopRecording() is launched. Flag stop is set to true.
StopRecording calls waits for thread "captureThread.Join();".
When recording thread detects stop flag, then it calls Dispose().
Dispose() calls again StopRecording(), but we already were here and we are waiting for thread. So thread.Join is called for the second time, and we have deadlock problem.
I avoided this problem with extending condition in StopRecording():
if (this.captureThread != null && this.stop == false)
if (this.captureThread != null)