private void CreateSubscription <TMessage>(IMessangerSubscription subscription) { ICollection <IMessangerSubscription> messangerSubscription; if (subscriptionsDictionary.TryGetValue(typeof(TMessage), out messangerSubscription)) { messangerSubscription.Add(subscription); subscriptionsDictionary[typeof(TMessage)] = messangerSubscription; } else { messangerSubscription = new Collection <IMessangerSubscription>(); messangerSubscription.Add(subscription); subscriptionsDictionary.Add(typeof(TMessage), messangerSubscription); } }
/// <summary> /// Method used for invoking subsciption method on new task (thread) /// </summary> /// <param name="subscriptions">method subscription</param> /// <param name="obj">argument</param> private void ExecuteOnNewThread(IMessangerSubscription subscriptions, object obj) { Task.Factory.StartNew(() => subscriptions.Execute(obj)); }
/// <summary> /// Method used for invoking subscription method on Caller thread. /// </summary> /// <param name="subscriptions">method subscription</param> /// <param name="obj">argument</param> private void ExecuteOnCallingTrherad(IMessangerSubscription subscriptions, object obj) { subscriptions.Execute(obj); }
/// <summary> /// Method used for invoking subsciption method on UI Dispatcher thread /// </summary> /// <param name="subscriptions">method subscription</param> /// <param name="obj">argument</param> private void ExecuteOnDispatcher(IMessangerSubscription subscriptions, object obj) { Dispatcher.CurrentDispatcher.Invoke(() => subscriptions.Execute(obj)); }