WasapiCapture.Dispose causes freeze
See original GitHub issueMy app uses WasapiCapture to record Windows and it nearly always works perfectly. But very, very occasionally, it freezes during the call to Dispose. I checked the source code, and I see this code
if (captureThread != null)
{
captureThread.Join();
captureThread = null;
}
That Join call is a likely candidate for causing a freeze, but I still can’t figure out what would cause this, or how to prevent it. It feels like something is causing the thread to remain alive, but because the problem is so rare, it’s hard to research further.
Any ideas on what to do about this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Crash in WasapiCapture when device is unplugged #772
@loics2 When an audio endpoint device is unplugged, the MMDevice.AudioClient is released or "disposed", along with its AudioClient.
Read more >c# - Program hangs after calling Dispose()
The core issue is that you are trying to close the camera while its callback is still executing, there's not a lot of...
Read more >Solved: My C# application hangs on closing main form at ...
The full query of 24000 records takes several minutes to close the form. It always hangs at components.Dispose() in the form Dispose method....
Read more >https://cgit.freedesktop.org/gstreamer/gst-plugins...
This fixes crash when use in zero-copy with videorate element. ... causing a crash when writing the mpd file. gst-launch-1.0 videotestsrc num-buffers=900 ...
Read more >Untitled
Basilica e chiesa differenza, Tongue tied baby causes, Zeiss 16-80 review, ... Extra beat rap instrumental, Sewage disposal methods, Kommunity fk the vision ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After putting this down for a long time, I had to revisit it and I think I found the source of the issue. It turns out that the capture thread is calling a notification callback on the UI thread, which can’t respond because the main thread is waiting for the capture thread via the join call. IOW, a deadlock caused by my own code. When I have some time, I will document this in a bit more detail, in case anyone else comes across this issue in the future.
Note to future readers, I had the same issue as the OP.
I fixed the problem by using
BeginInvoke
rather thanInvoke
when updating my UI from the callback.