/// <summary> /// Called when this viewmodel shall perform cleanup work prior to it being disposed. /// </summary> /// <exception cref="System.ObjectDisposedException">Thrown if the model was already disposed.</exception> public void Dispose() { if (this.IsDisposed) { throw new ObjectDisposedException(this.GetType().Name); } try { // first, do a custom dispose // we need to do this inside a try-catch because: // - the application can shut down, but the finalizer may come up // - then, dispose() is called... we never know what user-code is executed! this.DisposeInner(); } catch (Exception ex) { if (Application.Current != null) { // only throw this exception if the application is running, see remark above throw ex; } // either way, trace this System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Warning: Exception of type '{0}' caught while disposing object of type '{1}'. The error message was: {2}", ex.GetType().Name, this.GetType().Name, ex.Message)); } // automatically unwire commands? if (AutomaticUnwireCommands) { CommandHelper.UnwireRelayCommands(this); } // mark instance as disposed this.IsDisposed = true; // avoid calls to finalizer GC.SuppressFinalize(this); }
/// <summary> /// Called when this viewmodel shall perform cleanup work prior to it being disposed. /// </summary> /// <exception cref="System.ObjectDisposedException">Thrown if the model was already disposed.</exception> protected override void DisposeCore() { CommandHelper.UnwireRelayCommands(this); }