I'm receiving a COM error after my app exits if I call UnRegisterEventClient.
Here is a code snippet:
private Dictionary<uint, SessionsEventCallbacks.NAudioEventCallbacks> _sessionNotifications = new Dictionary<uint, SessionsEvents.NAudioEventCallbacks>();
// NAudioEventCallbacks inherits from IAudioSessionEventsHandler
...
private void OnSessionCreated(object sender, IAudioSessionControl newSession)
{
AudioSessionControl audioSession = new AudioSessionControl(newSession);
SessionsEvents.NAudioEventCallbacks notifications = new SessionsEventCallbacks.NAudioEventCallbacks();
notifications.contentCat = 0;
notifications.programType = 0;
notifications.processId = (int)audioSession.GetProcessID;
notifications.processName = Process.GetProcessById((int)audioSession.GetProcessID).ProcessName;
notifications.domain = string.Empty;
notifications.youtubeCategory = string.Empty;
notifications.audioSession = audioSession;
notifications.SessionEndedCallback = AudioStopped;
_sessionNotifications.Add((uint)notifications.processId, notifications);
audioSession.RegisterEventClient(notifications);
}
I call UnRegisterEventClient from AudioStopped.
Any help would be greatly appreciated!
Thanks,
Randall Deetz
Comments: I'm noticing that after calling UnRegisterEventClient, if I change audioSessionEventCallback to null in the debugger, the problem goes away.
Here is a code snippet:
private Dictionary<uint, SessionsEventCallbacks.NAudioEventCallbacks> _sessionNotifications = new Dictionary<uint, SessionsEvents.NAudioEventCallbacks>();
// NAudioEventCallbacks inherits from IAudioSessionEventsHandler
...
private void OnSessionCreated(object sender, IAudioSessionControl newSession)
{
AudioSessionControl audioSession = new AudioSessionControl(newSession);
SessionsEvents.NAudioEventCallbacks notifications = new SessionsEventCallbacks.NAudioEventCallbacks();
notifications.contentCat = 0;
notifications.programType = 0;
notifications.processId = (int)audioSession.GetProcessID;
notifications.processName = Process.GetProcessById((int)audioSession.GetProcessID).ProcessName;
notifications.domain = string.Empty;
notifications.youtubeCategory = string.Empty;
notifications.audioSession = audioSession;
notifications.SessionEndedCallback = AudioStopped;
_sessionNotifications.Add((uint)notifications.processId, notifications);
audioSession.RegisterEventClient(notifications);
}
I call UnRegisterEventClient from AudioStopped.
Any help would be greatly appreciated!
Thanks,
Randall Deetz
Comments: I'm noticing that after calling UnRegisterEventClient, if I change audioSessionEventCallback to null in the debugger, the problem goes away.