Skip to content

Commit

Permalink
fix potential freezes and crashes in instant connect/disconnect scena…
Browse files Browse the repository at this point in the history
…rios

couple things discovered from network issues causing instant connect/disconnect:
- Join() could block forever in some cases, so try to slam shut first and not block the wpf dispatcher
- captureThread could be nulled out while dispose was executing on other thread
  • Loading branch information
DexterHaslem committed Jun 4, 2022
1 parent eaf5fdc commit 42f8751
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions NAudio/Wave/WaveInputs/WasapiCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ private void CaptureThread(AudioClient client)
client.Stop();
// don't dispose - the AudioClient only gets disposed when WasapiCapture is disposed
}
captureThread = null;
// dont nuke our captureThread reference here, dispose also checks it
// captureThread = null;
captureState = CaptureState.Stopped;
RaiseRecordingStopped(exception);
}
Expand Down Expand Up @@ -356,7 +357,11 @@ public void Dispose()
StopRecording();
if (captureThread != null)
{
captureThread.Join();
if (captureThread.IsAlive)
{
captureThread.Abort();
captureThread.Join();
}
captureThread = null;
}
if (audioClient != null)
Expand Down

0 comments on commit 42f8751

Please sign in to comment.