question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WasapiCapture.Dispose causes freeze

See original GitHub issue

My 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:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jfrank14commented, Jan 6, 2021

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.

0reactions
Zintomcommented, Oct 3, 2022

Note to future readers, I had the same issue as the OP.

I fixed the problem by using BeginInvoke rather than Invoke when updating my UI from the callback.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found