static public void Run (CompressedStack compressedStack, ContextCallback callback, object state) { if (compressedStack == null) throw new ArgumentException ("compressedStack"); Thread t = Thread.CurrentThread; CompressedStack original = null; try { original = t.GetCompressedStack (); t.SetCompressedStack (compressedStack); callback (state); } finally { if (original != null) t.SetCompressedStack (original); } }
/// <summary>Runs a method in the specified compressed stack on the current thread.</summary> /// <param name="compressedStack">The <see cref="T:System.Threading.CompressedStack" /> to set.</param> /// <param name="callback">A <see cref="T:System.Threading.ContextCallback" /> that represents the method to be run in the specified security context.</param> /// <param name="state">The object to be passed to the callback method.</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="compressedStack" /> is null.</exception> public static void Run(CompressedStack compressedStack, ContextCallback callback, object state) { if (compressedStack == null) { throw new ArgumentException("compressedStack"); } Thread currentThread = Thread.CurrentThread; CompressedStack compressedStack2 = null; try { compressedStack2 = currentThread.GetCompressedStack(); currentThread.SetCompressedStack(compressedStack); callback(state); } finally { if (compressedStack2 != null) { currentThread.SetCompressedStack(compressedStack2); } } }