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)
instead of
if (this.captureThread != null)
Regards.
Piotr.
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)
instead of
if (this.captureThread != null)
Regards.
Piotr.