markheath wrote:
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:
Please comment if you would like this moved to the Issues section.
Jake
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. MarkSorry 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