static public CompressedStack GetCompressedStack() { #if !FEATURE_COMPRESSEDSTACK throw new NotSupportedException(); #else // Note: CompressedStack.GetCompressedStack doesn't return null // like Thread.CurrentThread.GetCompressedStack if no compressed // stack is present. CompressedStack cs = Thread.CurrentThread.ExecutionContext.SecurityContext.CompressedStack; if (cs == null || cs.IsEmpty()) { cs = CompressedStack.Capture(); } else { cs = cs.CreateCopy(); // merge the existing compressed stack (from a previous Thread) with the current // Thread stack so we can assign "all of it" to yet another Thread CompressedStack newstack = CompressedStack.Capture(); for (int i = 0; i < newstack._list.Count; i++) { cs._list.Add(newstack._list [i]); } } return(cs); #endif }
static public CompressedStack GetCompressedStack () { // Note: CompressedStack.GetCompressedStack doesn't return null // like Thread.CurrentThread.GetCompressedStack if no compressed // stack is present. CompressedStack cs = Thread.CurrentThread.GetCompressedStack (); if (cs == null) { cs = CompressedStack.Capture (); } else { // merge the existing compressed stack (from a previous Thread) with the current // Thread stack so we can assign "all of it" to yet another Thread CompressedStack newstack = CompressedStack.Capture (); for (int i=0; i < newstack._list.Count; i++) cs._list.Add (newstack._list [i]); } return cs; }
/// <summary>Gets the compressed stack for the current thread.</summary> /// <returns>A <see cref="T:System.Threading.CompressedStack" /> for the current thread.</returns> /// <exception cref="T:System.Security.SecurityException">A caller in the call chain does not have permission to access unmanaged code.-or-The request for <see cref="T:System.Security.Permissions.StrongNameIdentityPermission" /> failed.</exception> /// <filterpriority>1</filterpriority> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// <IPermission class="System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PublicKeyBlob="00000000000000000400000000000000" /> /// </PermissionSet> public static CompressedStack GetCompressedStack() { CompressedStack compressedStack = Thread.CurrentThread.GetCompressedStack(); if (compressedStack == null) { compressedStack = CompressedStack.Capture(); } else { CompressedStack compressedStack2 = CompressedStack.Capture(); for (int i = 0; i < compressedStack2._list.Count; i++) { compressedStack._list.Add(compressedStack2._list[i]); } } return(compressedStack); }