When I was doing some UI testing, I found few common exceptions.
For example when calling handler (directsoundout.cs, line 451):
// Fire playback stopped event
if (PlaybackStopped != null)
{
if (this.syncContext == null)
{
PlaybackStopped(this, EventArgs.Empty);
}
else
{
syncContext.Post(state => PlaybackStopped(this, EventArgs.Empty), null);
}
}
it should be written like this, because syncContext.Post will sooner or later throw nullreferenceexcepion. Playbackstopped could be null at this time.
var handler = PlaybackStopped;
// Fire playback stopped event
if (handler != null)
{
if (this.syncContext == null)
{
handler(this, EventArgs.Empty);
}
else
{
syncContext.Post(state => handler(this, EventArgs.Empty), null);
}
}
I think all the code needs revision , which is not so big deal. I could help you to write some UI, with UIautomation testing, which I think is the best way to test stuff like this, especially when it comes to thread safety.
Comments: If you don't mind I will write here issues which a think are related to thread safety. When disposing DirectSoundOut which is in playing state, and NullReferenceException occurs. I added private bool disposing = false; then is Dispose set it to true and in Feed method: if (disposing) return 0; this worked for me;.
For example when calling handler (directsoundout.cs, line 451):
// Fire playback stopped event
if (PlaybackStopped != null)
{
if (this.syncContext == null)
{
PlaybackStopped(this, EventArgs.Empty);
}
else
{
syncContext.Post(state => PlaybackStopped(this, EventArgs.Empty), null);
}
}
it should be written like this, because syncContext.Post will sooner or later throw nullreferenceexcepion. Playbackstopped could be null at this time.
var handler = PlaybackStopped;
// Fire playback stopped event
if (handler != null)
{
if (this.syncContext == null)
{
handler(this, EventArgs.Empty);
}
else
{
syncContext.Post(state => handler(this, EventArgs.Empty), null);
}
}
I think all the code needs revision , which is not so big deal. I could help you to write some UI, with UIautomation testing, which I think is the best way to test stuff like this, especially when it comes to thread safety.
Comments: If you don't mind I will write here issues which a think are related to thread safety. When disposing DirectSoundOut which is in playing state, and NullReferenceException occurs. I added private bool disposing = false; then is Dispose set it to true and in Feed method: if (disposing) return 0; this worked for me;.