/// <summary>
        /// This method returns an enumerable view of the bag, and returns it to
        /// an internal pool for reuse by GetOrCreate().
        ///
        /// It is not thread safe.
        ///
        /// It should only be called once the bag is finished being mutated.
        /// </summary>
        public ProfiledCommandEnumerable EnumerateAndReturnForReuse()
        {
            var ret = new ProfiledCommandEnumerable(Head);

            ReturnForReuse();

            return(ret);
        }
Example #2
0
        /// <summary>
        /// Removes a context, setting all commands to a (non-thread safe) enumerable of
        /// all the commands attached to that context.
        ///
        /// If the context was never registered, will return false and set commands to null.
        ///
        /// Subsequent calls to TryRemove with the same context will return false unless it is
        /// re-registered with TryCreate.
        /// </summary>
        /// <param name="ctx">The context to remove for.</param>
        /// <param name="commands">The commands to remove.</param>
        public bool TryRemove(object ctx, out ProfiledCommandEnumerable commands)
        {
            var cell = ProfileContextCell.ToLookupBy(ctx);

            if (!profiledCommands.TryRemove(cell, out ConcurrentProfileStorageCollection storage))
            {
                commands = default(ProfiledCommandEnumerable);
                return(false);
            }

            commands = storage.EnumerateAndReturnForReuse();
            return(true);
        }