/// <summary> /// Dispose of all resources in an orderly fashion. /// </summary> public override void Dispose() { if (aboutBox != null) { aboutBox.Dispose(); aboutBox = null; } if (tracker != null) { tracker.Dispose(); tracker = null; } if (librarian != null) { librarian.CollectionChanged -= DoTaskCollectionChanged; librarian.Dispose(); librarian = null; } if (controller != null) { controller.LyricsProgressReport -= DoLyricsProgressReport; controller.LyricsUpdated -= DoLyricsUpdated; controller.Quiting -= DoQuiting; controller.TrackPlaying -= DoTrackPlaying; controller.TrackStopped -= DoTrackStopped; // if running from IDE force iTunes to shutdown, force COM detach. Poking around // in the debugger tends to destabalize the COM interface so we shut it down when // invoked from the Debugger to avoid any confusion. controller.Dispose(System.Diagnostics.Debugger.IsAttached); controller = null; } if (manager != null) { manager.KeyPressed -= ExecuteHotKeyAction; manager.Dispose(); manager = null; } if (trayIcon != null) { trayIcon.ContextMenu.Popup -= SetMenuItemStates; trayIcon.ContextMenu.Dispose(); trayIcon.ContextMenu = null; trayIcon.MouseDown -= DoTrayIconMouseDown; trayIcon.Dispose(); trayIcon = null; } base.Dispose(); isDisposed = true; }
/// <summary> /// Now that iTunes is started, we can continue initializing the iTuner UI /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DoLoadingCompleted(object sender, RunWorkerCompletedEventArgs e) { if (controller == null) { Close(); return; } controller.LyricsProgressReport += DoLyricsProgressReport; controller.LyricsUpdated += DoLyricsUpdated; controller.Quiting += DoQuiting; controller.TrackPlaying += DoTrackPlaying; controller.TrackStopped += DoTrackStopped; librarian.CollectionChanged += DoTaskCollectionChanged; if (splash != null) { splash.Hide(); splash = null; } DataContext = controller; manager = new KeyManager(); manager.KeyPressed += ExecuteHotKeyAction; trayIconTimer = new WinForms.Timer { Interval = WinForms.SystemInformation.DoubleClickTime }; trayIconTimer.Tick += DoTrayIconTick; trayIconClickCount = 0; tracker = new TrackerWindow(controller); EventManager.RegisterClassHandler( typeof(EditBlock), EditBlock.BeginEditEvent, new RoutedEventHandler(DoBeginEdit)); EventManager.RegisterClassHandler( typeof(EditBlock), EditBlock.CompleteEditEvent, new RoutedEventHandler(DoCompleteEdit)); isDisposed = false; syncdis = new object(); SetNotifyIcon(controller.CurrentTrack); }