Every once in a while when I close my application while using WaveOutEvent i get a NullReferenceException from the DoPlayback() function. It turns out this.buffers is null.
Screenshot from VS2010, when Exception happens
A bandaid to fix the problem I now check for the null value in DoPlayback();
private void DoPlayback() { if (this.buffers == null || this.waveStream == null) return; TimeSpan waitTime = TimeSpan.FromSeconds((double)this.buffers[0].BufferSize / (this.waveStream.WaveFormat.AverageBytesPerSecond * 2)); ......... }
I dont get a good stack trace back for some reason, I assume the call to DoPlayback() is still in the ThreadPool after I dispose of WaveOutEvent?
ThreadPool.QueueUserWorkItem((state) => PlaybackThread(), null);
Maybe the cure (not bandaid) would be to "un-queue" the thread form the pool on disposal? not sure if that is possible or makes any sense...
I hope this helps, or maybe I am just doing something wrong...
Thanks,
Brandon Hansen, KG6YPI
ps.. I noticed my callsign (kg6ypi) got into the readme file, you can attach my name to it also if you wish, thanks.