Ejemplo n.º 1
0
        /// <summary>
        /// Executes the specified action on a thread associated with object's dispatcher.
        /// This invokes a InvokeAsync on the Dispatcher, does not wait for the action
        /// to complete -- returns immediately.
        /// </summary>
        /// <param name="action">An action to execute.</param>
        /// <returns>A task that completes when action has completed.</returns>
        private async Task CheckAccessInvokeAsync(Action action)
        {
            ArgumentValidation.NotNull(action, "action");

            if (this.dispatcher.CheckAccess())
            {
                action();
            }
            else
            {
                await this.dispatcher.InvokeAsync(action, DispatcherPriority.Normal);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new transformed collection wrapping a source collection.
        /// </summary>
        /// <param name="sourceCollection">The source collection that this collection wraps.</param>
        /// <param name="setup">The logic for creating a transformed element from a source element.</param>
        /// <param name="teardown">The logic for destroying a transformed element when removed from the transformed collection.</param>
        public TransformedDispatcherCollection(Dispatcher dispatcher, TSourceCollection sourceCollection, Func <TSourceElement, TTargetElement> setup, Action <TTargetElement> teardown = null) :
            base(new List <TTargetElement>(sourceCollection.Select(setup)))
        {
            ArgumentValidation.NotNull(dispatcher, "dispatcher");
            ArgumentValidation.NotNull(sourceCollection, "sourceCollection");
            ArgumentValidation.NotNull(setup, "setup");

            this.setup    = setup;
            this.teardown = teardown;

            this.dispatcher       = dispatcher;
            this.sourceCollection = sourceCollection;
            CollectionChangedEventManager.AddListener(this.sourceCollection, this);
        }