//======================================================================================== // Constructors //======================================================================================== /// <summary> /// Initialize class static fields. /// </summary> static Interaction() { enabledEvent = new _IiTunesEvents_OnCOMCallsEnabledEventEventHandler(DoEnabledEvent); disabledEvent = new _IiTunesEvents_OnCOMCallsDisabledEventEventHandler(DoDisabledEvent); reset = new ManualResetEvent(true); isConnected = false; }
//======================================================================================== // Constructors //======================================================================================== /// <summary> /// Initialize class static fields. /// </summary> static Interaction() { enabledEvent = DoEnabledEvent; disabledEvent = DoDisabledEvent; reset = new ManualResetEvent(true); isConnected = false; }
//======================================================================================== // Constructors //======================================================================================== /// <summary> /// Initialize class static fields. /// </summary> static Interaction() { enabledEvent = new _IiTunesEvents_OnCOMCallsEnabledEventEventHandler(DoEnabledEvent); disabledEvent = new _IiTunesEvents_OnCOMCallsDisabledEventEventHandler(DoDisabledEvent); itunes = new iTunesAppClass(); itunes.OnCOMCallsEnabledEvent += enabledEvent; itunes.OnCOMCallsDisabledEvent += disabledEvent; reset = new ManualResetEvent(true); }
/// <summary> /// Dispose of this instance, optionally exiting iTunes. /// </summary> /// <param name="finalRelease"><b>true</b> to exit iTunes.</param> public void Dispose(bool finalRelease) { if (!isDisposed) { // invoke Cleanup on behalf of the derived class Cleanup(finalRelease); if (isPrimaryController) { isConnected = false; if (itunes != null) { try { itunes.OnCOMCallsDisabledEvent -= disabledEvent; itunes.OnCOMCallsEnabledEvent -= enabledEvent; } catch (InvalidComObjectException) { // RCW may be released already... why? } disabledEvent = null; enabledEvent = null; if (finalRelease) { try { itunes.Quit(); } catch { // no-op } finally { Release(itunes); itunes = null; } } reset.Set(); reset.Close(); reset = null; } } isDisposed = true; GC.SuppressFinalize(this); } }
/// <summary> /// Dispose of this instance; do not override. /// </summary> public void Dispose() { if (!isDisposed) { // invoke Cleanup on behalf of the derived class Cleanup(); if (isPrimaryController) { isConnected = false; if (itunes != null) { itunes.OnCOMCallsDisabledEvent -= disabledEvent; itunes.OnCOMCallsEnabledEvent -= enabledEvent; disabledEvent = null; enabledEvent = null; try { itunes.Quit(); } catch { // no-op } finally { Release(itunes); itunes = null; } reset.Set(); reset.Close(); reset = null; } } isDisposed = true; GC.SuppressFinalize(this); } }
public void iTunes() { itunes = new iTunesAppClass(); aboutToPromptUserToQuitEvent = new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(itunes_OnAboutToPromptUserToQuitEvent); cOMCallsDisabledEvent = new _IiTunesEvents_OnCOMCallsDisabledEventEventHandler(itunes_OnCOMCallsDisabledEvent); cOMCallsEnabledEvent = new _IiTunesEvents_OnCOMCallsEnabledEventEventHandler(itunes_OnCOMCallsEnabledEvent); databaseChangedEvent = new _IiTunesEvents_OnDatabaseChangedEventEventHandler(itunes_OnDatabaseChangedEvent); playerPlayEvent = new _IiTunesEvents_OnPlayerPlayEventEventHandler(itunes_OnPlayerPlayEvent); playerPlayingTrackChangedEvent = new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(itunes_OnPlayerPlayingTrackChangedEvent); playerStopEvent = new _IiTunesEvents_OnPlayerStopEventEventHandler(itunes_OnPlayerStopEvent); quittingEvent = new _IiTunesEvents_OnQuittingEventEventHandler(itunes_OnQuittingEvent); soundVolumeChangedEvent = new _IiTunesEvents_OnSoundVolumeChangedEventEventHandler(itunes_OnSoundVolumeChangedEvent); userInterfaceEnabledEvent = new _IiTunesEvents_OnUserInterfaceEnabledEventEventHandler(itunes_OnUserInterfaceEnabledEvent); // NOTE: did not see any difference in maintaining these individual handler variables // as opposed to unregistering -= new handlers in the OnAboutToPromptToQuit handler itunes.OnAboutToPromptUserToQuitEvent += aboutToPromptUserToQuitEvent; itunes.OnCOMCallsDisabledEvent += cOMCallsDisabledEvent; itunes.OnCOMCallsEnabledEvent += cOMCallsEnabledEvent; itunes.OnDatabaseChangedEvent += databaseChangedEvent; itunes.OnPlayerPlayEvent += playerPlayEvent; itunes.OnPlayerPlayingTrackChangedEvent += playerPlayingTrackChangedEvent; itunes.OnPlayerStopEvent += playerStopEvent; itunes.OnQuittingEvent += quittingEvent; itunes.OnSoundVolumeChangedEvent += soundVolumeChangedEvent; itunes.OnUserInterfaceEnabledEvent += userInterfaceEnabledEvent; AllProps(itunes); reset = new ManualResetEvent(false); // waiting for iTunes to quit reset.WaitOne(); }