/// <summary> /// End call context /// </summary> /// <param name="nodeId">Id of the context node</param> /// <remarks>This method may be called by multiple threads</remarks> public void EndCallContext(Guid?nodeId) { if (nodeId.HasValue) { // We may be accessing this method from a different thread // Enqueue this node for removal once an end call context is called by this thread m_nodesToRemove.Enqueue(nodeId.Value); } else { if (!Exists) { RemoveEndedCallContexts(); #if DEBUG throw new InvalidOperationException("There is no active call context to end."); #else return; #endif } if (m_stackCount == 1) { m_data = null; } else { Guid lastGuid; lock (m_nodesDictionary) { lastGuid = (Guid)m_nodesDictionary.Cast <DictionaryEntry>().Last().Key; } m_nodesToRemove.Enqueue(lastGuid); } RemoveEndedCallContexts(); } Interlocked.Decrement(ref m_stackCount); }
public void RetainsOrder() { var dic = new OrderedDictionary <int, string>(); IDictionary <int, string> dicIntf = dic; IOrderedDictionary dicNonGeneric = dic; dic.Add(3, "three"); dic.Add(2, "two"); dic.Add(1, "one"); dicIntf.Add(new KeyValuePair <int, string>(0, "zero")); dic.Remove(2); dicIntf.Add(5, "five"); Assert.Equal(new[] { new KeyValuePair <int, string>(3, "three"), new KeyValuePair <int, string>(1, "one"), new KeyValuePair <int, string>(0, "zero"), new KeyValuePair <int, string>(5, "five") }, dic); Assert.Equal(new[] { new KeyValuePair <int, string>(3, "three"), new KeyValuePair <int, string>(1, "one"), new KeyValuePair <int, string>(0, "zero"), new KeyValuePair <int, string>(5, "five") }, dicNonGeneric.Cast <KeyValuePair <int, string> >()); var entries = new List <object>(); IDictionaryEnumerator enumerator = dicNonGeneric.GetEnumerator(); while (enumerator.MoveNext()) { entries.Add(enumerator.Current); } entries = new List <object>(); enumerator = ((IDictionary)dic).GetEnumerator(); while (enumerator.MoveNext()) { entries.Add(enumerator.Current); } enumerator.Reset(); enumerator.MoveNext(); Assert.Equal(3, enumerator.Key); Assert.Equal("three", enumerator.Value); Assert.Equal(new object[] { new DictionaryEntry(3, "three"), new DictionaryEntry(1, "one"), new DictionaryEntry(0, "zero"), new DictionaryEntry(5, "five") }, entries); Assert.Equal(new[] { 3, 1, 0, 5 }, dic.Keys); Assert.Equal(new[] { 3, 1, 0, 5 }, dicNonGeneric.Keys); Assert.Equal(new[] { "three", "one", "zero", "five" }, dic.Values); Assert.Equal(new[] { "three", "one", "zero", "five" }, dicNonGeneric.Values); }