/// <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); }
/// <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> public bool TryRemove(object ctx, out ProfiledCommandEnumerable commands) { var cell = ProfileContextCell.ToLookupBy(ctx); ConcurrentProfileStorageCollection storage; if (!profiledCommands.TryRemove(cell, out storage)) { commands = default(ProfiledCommandEnumerable); return(false); } commands = storage.EnumerateAndReturnForReuse(); return(true); }