private static void CheckSoundEffectInstanceState() { foreach (var state in States.ToList()) { if (state.Key != null && !state.Key.IsDisposed) { if (state.Value != state.Key.State) { var e = new SoundStateChangedEventArgs() { Instance = state.Key, OldState = state.Value }; States[state.Key] = state.Key.State; if (SoundStateChanged != null) { SoundStateChanged(null, e); } } } } }
void AudioManager_SoundStateChanged(object sender, SoundStateChangedEventArgs e) { lock (Sync) { //For some reason sometimes the playinginstance just says it's Null which is BS //and when it's null it will crash it, so we check it before we try to change it //It's weird as the sound will still get updated to finished when it's done so the random null //is utter bullshit. if (PlayingInstance != null && !PlayingInstance.IsDisposed) { Application.Current.Dispatcher.BeginInvoke( new Action(() => SoundState = PlayingInstance.State)); } } }