i have this list of sounds:
List<SourceVoice> runningInstances;
i attach an event to a sound object so that i remove it from the list when it is stopped.
sourceVoice.StreamEnd += delegate
{
lock (runningInstances)
{
runningInstances.Remove(sourceVoice);
}
};
and i also have this stop function, which is called from any thread.
public void stop(int fadeoutTime)
{
lock (runningInstances)
{
foreach (var sourceVoice in runningInstances)
{
if (!sourceVoice.IsDisposed)
{
sourceVoice.Stop();
sourceVoice.FlushSourceBuffers();
sourceVoice.DestroyVoice();
sourceVoice.Dispose();
}
}
runningInstances.Clear();
}
}
i thought that since i make the event a delegate, it will always wait until the object is unlocked. however it seems that it freezes there.