示例#1
0
        /// <summary>
        /// Detaches the event source.
        /// </summary>
        /// <param name="item">The item to detach.</param>
        protected void DetachEventSource([NotNull] INotifyPropertyChanged item)
        {
            var sourceType = item.GetType();

            if (EventSources.TryGetValue(sourceType, out var oldListener) && oldListener.TryGetTarget(out var target))
            {
                target.PropertyChanged -= RelaySource_PropertyChanged;
                EventSources.Remove(sourceType);
            }
        }
        /// <summary>
        /// Detaches the event source.
        /// </summary>
        /// <param name="item">The item to detach.</param>
        protected void DetachEventSource([NotNull] INotifyPropertyChanged item)
        {
            var sourceType = item.GetType();

            if (EventSources.TryGetValue(sourceType, out var oldListern))
            {
                oldListern?.Detach();
                EventSources.Remove(sourceType);
            }
        }
 /// <summary>
 /// Detaches the event source.
 /// </summary>
 /// <param name="item">The item to detach.</param>
 protected void DetachEventSource([NotNull] INotifyPropertyChanged item)
 {
     Contract.Requires(item != null);
     item.PropertyChanged -= RelaySource_PropertyChanged;
     EventSources.Remove(item.GetType());
 }
示例#4
0
        public static void Unload(AppDomain domain)
        {
            var assembly = domain.GetAssemblies()[1];
            var filePath = assembly.CodeBase;

            Commands.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => Commands.Remove(c));
            EventConsumers.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => EventConsumers.Remove(c));
            EventSources.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => EventSources.Remove(c));
            Services.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => { c.Stop(); Services.Remove(c); });
            Bindings.Where(c => assembly == c.GetType().Assembly).ToList().ForEach(c => Bindings.Remove(c));
            Domains.Remove(domain);
            AppDomain.Unload(domain);
            GC.Collect();                  // collects all unused memory
            GC.WaitForPendingFinalizers(); // wait until GC has finished its work
            GC.Collect();

            //File.Delete(filePath);
        }