'C# WPF window resize is blocking NAudio WaveIn / WaveOut stream

I´m using NAudio and WPF to develop a mixer software in C#.

But I have faced with a non commum behaivour: the output is playing normally, but when I resize the MainWindow, output audio starts spliting. If keep window resize, buffer got full and a exception is throw. It´s looks like resize event is blocking the main thread.

Has someone any suggestion?

_wavein = new WaveIn();
_wavein.DeviceNumber = 0;
_wavein.WaveFormat = new WaveFormat(44100, WaveIn.GetCapabilities(0).Channels);
    
waveInProvider = new WaveInProvider(_wavein);
    
volumeSampleProvider = new VolumeSampleProvider(waveInProvider.ToSampleProvider());
volumeSampleProvider.Volume = (float)slider.Value;
    
MeteringSampleProvider meteringSampleProvider = new MeteringSampleProvider(volumeSampleProvider, 1000);
meteringSampleProvider.StreamVolume += meteringSampleProviderStreamVolume;
    
_waveOut = new WaveOut();
_waveOut.DesiredLatency = 50;
_waveOut.Init(meteringSampleProvider.ToWaveProvider());

_wavein.StartRecording();
_waveOut.Play();


Solution 1:[1]

If you use WaveOutEvent and WaveOutEvent the audio processing will happen on a background thread which should help considerably

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark Heath