Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: NullReferenceException in WaveOutEvent

$
0
0
markheath wrote:
good stuff. I had assumed syncContext would be null on web servers. It was just added as a convenient way to make WinForms and WPF work. Mark
Sorry to resurrect an old thread, but I had this problem come back when I updated to NAudio 1.7.
At first I put in the same fix that was mentioned in the previous post - but then I realized that was only going to work for my ASP application and probably wouldn't work for WinForms. So, here is the code I am using now:
        private void RaisePlaybackStoppedEvent(Exception e)
        {
            var handler = PlaybackStopped;
            if (handler != null)                                    // anyone to notify?
            {
                if ((this.syncContext == null) || (this.syncContext.GetType() != typeof(System.Windows.Forms.WindowsFormsSynchronizationContext)))
                {
                    handler(this, new StoppedEventArgs(e));
                }
                else
                {
                    this.syncContext.Post(state => handler(this, new StoppedEventArgs(e)), null);
                }
            }
        }
    }
It works for the case where syncContext is null, and when it is an ASP context, and should work same as previous for a Winforms context.

Please comment if you would like this moved to the Issues section.

Jake

Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>