protected override void Dispose(bool disposing)
{
if (disposing)
{
// Dispose managed
}
// Dispose unmanaged
if (!IsInvalid)
{
try
{
_mainThreadNotification.Set();
lock (_eventQueueLock)
{
Monitor.Pulse(_eventQueueLock);
}
if (_callbacks != null)
{
_callbacks.Dispose();
_callbacks = null;
}
PlaylistTrackManager.RemoveAll(this);
TrackManager.DisposeAll(this);
LinkManager.RemoveAll(this);
UserManager.RemoveAll(this);
PlaylistContainerManager.RemoveAll(this);
PlaylistManager.RemoveAll(this);
ContainerPlaylistManager.RemoveAll(this);
ArtistManager.RemoveAll();
AlbumManager.RemoveAll();
SessionManager.Remove(Handle);
lock (Spotify.Mutex)
{
Error error = Error.OK;
if (ConnectionState == ConnectionState.LoggedIn)
{
error = Spotify.sp_session_logout(Handle);
Debug.WriteLineIf(error != Error.OK, error.GetMessage());
}
error = Spotify.sp_session_release(Handle);
Debug.WriteLineIf(error != Error.OK, error.GetMessage());
Handle = IntPtr.Zero;
}
}
catch
{
// Ignore
}
finally
{
Debug.WriteLine("Session disposed");
}
}
base.Dispose(disposing);
}