public static void Unsubscribe <TPayload>(Action <TPayload> subscriber)
 {
     lock (_subscriptions)
     {
         ChannelSubscription <TPayload> eventSubscription = _subscriptions.Cast <ChannelSubscription <TPayload> >().FirstOrDefault(evt => evt.Action == subscriber);
         if (eventSubscription != null)
         {
             _subscriptions.Remove(eventSubscription);
         }
     }
 }
        public static ChannelSubscriptionToken Subscribe <TPayload>(Action <TPayload> action, ThreadOption threadOption, bool keepSubscriberReferenceAlive, Predicate <TPayload> filter)
        {
            DelegateReference actionReference = new DelegateReference(action, keepSubscriberReferenceAlive);
            DelegateReference filterReference;

            filterReference = filter != null ? new DelegateReference(filter, keepSubscriberReferenceAlive) : new DelegateReference(new Predicate <TPayload>(obj => true), true);

            ChannelSubscription <TPayload> subscription;

            switch (threadOption)
            {
            case ThreadOption.PublisherThread:
                subscription = new ChannelSubscription <TPayload>(actionReference, filterReference);
                break;

            case ThreadOption.BackgroundThread:
                //    subscription = new BackgroundEventSubscription<TPayload>(actionReference, filterReference);
                throw new NotImplementedException();

            case ThreadOption.UIThread:
                subscription = new DispatcherChannelSubscription <TPayload>(actionReference, filterReference, UIDispatcher);
                break;

            default:
                subscription = new ChannelSubscription <TPayload>(actionReference, filterReference);
                break;
            }


            //return base.InternalSubscribe(subscription);
            subscription.SubscriptionToken = new ChannelSubscriptionToken();
            lock (_subscriptions)
            {
                _subscriptions.Add(subscription);
            }
            return(subscription.SubscriptionToken);
        }