I call WaveOut.GetPosition up to 60 times per second to sync an animation, and when using the Callback strategy, I get deadlocks very quickly (within 20-30 seconds) and consistently (all the time). I've [described the problem in more detail](http://stackoverflow.com/a/16468906/1174169) on Stack Overflow.
I made a change in WaveOut.Callback to delegate the work to the thread pool. I'm not sure if this is the best idea, as I'm not so familiar with the source of NAudio. Do you think this is a good idea? I've checked in the changes on [my NAudio fork](https://naudio.codeplex.com/SourceControl/network/forks/cod3monk3y/NAudio/changeset/1b3747e016b6).
I had to update the profile to 4.0 in order to use the `Task` class.
This solves the deadlock issue, and pretty much runs exactly the same way. The only difference (besides non deadlock) is that the thread running the callback isn't an OS thread. It's a thread pool thread.
Thanks!
/cm
Comments: Thanks for the comment, Mark.
I'm aware of the issues (clearly!) with the function callback strategy, [from your blog](http://mark-dot-net.blogspot.com/2011/05/naudio-audio-output-devices.html). It's just the only solution that works with our requirements. (Though not-deadlocking is certainly an implicit requirement!)
We *were* using Window callbacks, but even with "new window" the audio stutters during major changes in layout in a WPF app. Since the work is posted to the windows message pump, it must not be making it out in time to fill the buffer properly. I'm sure we could probably tune the app, but it's a large code base that was written by a former employee.
We tried increasing the `DesiredLatency` in window-strategy mode to ensure that there were 2-4 seconds of audio buffered which could get us through the transition. But this resulted in static playing back when the 2nd buffer was only partially full (short audio file) and other serious failures (like BSoD).
I'd be happy to try WaveOutEvent, but I need access to the current playback position which is only available through WaveOut. Or am I missing something?
Do you have any recommendations or pointers as to where I can get the current playback position using WaveOutEvent, or how to prioritize the messages using the New/Existing Window strategy so that the audio doesn't stutter?
Thanks!
/cm