当前位置: 首页>>代码示例>>C#>>正文


C# ExecutionContext.CreateCopy方法代码示例

本文整理汇总了C#中System.Threading.ExecutionContext.CreateCopy方法的典型用法代码示例。如果您正苦于以下问题:C# ExecutionContext.CreateCopy方法的具体用法?C# ExecutionContext.CreateCopy怎么用?C# ExecutionContext.CreateCopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.ExecutionContext的用法示例。


在下文中一共展示了ExecutionContext.CreateCopy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WrapBodyDelegate

 static BodyDelegate WrapBodyDelegate(ExecutionContext context, BodyDelegate body)
 {
     return body == null ? (BodyDelegate)null : (write, flush, end, cancellationToken) => ExecutionContext.Run(
         context.CreateCopy(),
         _ => body(write, WrapFlushDelegate(context, flush), end, cancellationToken),
         null);
 }
开发者ID:markrendle,项目名称:gate,代码行数:7,代码来源:ExecutionContextPerRequest.cs

示例2: WrapWriteDelegate

        static Func<ArraySegment<byte>, Action<Exception>, TempEnum> WrapWriteDelegate(ExecutionContext context, Func<ArraySegment<byte>, Action<Exception>, TempEnum> write)
        {
            return (data, callback) =>
            {
                if (callback == null)
                {
                    return write(data, null);
                }

                return write(data, ex => ExecutionContext.Run(context.CreateCopy(), state => callback((Exception)state), ex));
            };
        }
开发者ID:anurse,项目名称:gate,代码行数:12,代码来源:ExecutionContextPerRequest.cs

示例3: WrapBodyDelegate

        static BodyDelegate WrapBodyDelegate(ExecutionContext context, BodyDelegate body)
        {
            if (body == null)
            {
                return null;
            }

            return (write, end, cancellationToken) => ExecutionContext.Run(
                context.CreateCopy(),
                _ => body(WrapWriteDelegate(context, write), end, cancellationToken),
                null);
        }
开发者ID:anurse,项目名称:gate,代码行数:12,代码来源:ExecutionContextPerRequest.cs

示例4: CaptureOrComplete

 private bool CaptureOrComplete(ref ExecutionContext cachedContext, bool returnContext)
 {
     bool flag = (base.AsyncCallback != null) || ((this._Flags & StateFlags.CaptureContext) != StateFlags.None);
     if ((((this._Flags & StateFlags.CaptureIdentity) != StateFlags.None) && !base.InternalPeekCompleted) && (!flag || SecurityContext.IsWindowsIdentityFlowSuppressed()))
     {
         this.SafeCaptureIdenity();
     }
     if (flag && !base.InternalPeekCompleted)
     {
         if (cachedContext == null)
         {
             cachedContext = ExecutionContext.Capture();
         }
         if (cachedContext != null)
         {
             if (!returnContext)
             {
                 this._Context = cachedContext;
                 cachedContext = null;
             }
             else
             {
                 this._Context = cachedContext.CreateCopy();
             }
         }
     }
     else
     {
         cachedContext = null;
     }
     if (base.CompletedSynchronously)
     {
         base.Complete(IntPtr.Zero);
         return true;
     }
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:ContextAwareResult.cs

示例5: RunInternal

        internal static void RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, bool preserveSyncCtx)
        {
            Contract.Assert(executionContext != null);
            if (executionContext.IsPreAllocatedDefault)
            {
                Contract.Assert(executionContext.IsDefaultFTContext(preserveSyncCtx));
            }
            else
            {
                Contract.Assert(executionContext.isNewCapture);
                executionContext.isNewCapture = false;
            }

            Thread currentThread = Thread.CurrentThread;
            ExecutionContextSwitcher ecsw = default(ExecutionContextSwitcher);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                ExecutionContext.Reader ec = currentThread.GetExecutionContextReader();
                if ( (ec.IsNull || ec.IsDefaultFTContext(preserveSyncCtx)) && 
    #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK                
                    SecurityContext.CurrentlyInDefaultFTSecurityContext(ec) && 
    #endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK                
                    executionContext.IsDefaultFTContext(preserveSyncCtx))
                {
                    // Neither context is interesting, so we don't need to set the context.
                    // We do need to reset any changes made by the user's callback,
                    // so here we establish a "copy-on-write scope".  Any changes will
                    // result in a copy of the context being made, preserving the original
                    // context.
                    EstablishCopyOnWriteScope(currentThread, true, ref ecsw);
                }
                else
                {
                    if (executionContext.IsPreAllocatedDefault)
                        executionContext = executionContext.CreateCopy();
                    ecsw = SetExecutionContext(executionContext, preserveSyncCtx);
                }

                //
                // Call the user's callback
                //
                callback(state);
            }
            finally
            {
                ecsw.Undo(currentThread);
            }
        }
开发者ID:stormleoxia,项目名称:referencesource,代码行数:50,代码来源:executioncontext.cs

示例6: CaptureOrComplete

        // This must be called right before returning the result to the user.  It might call the callback itself,
        // to avoid flowing context.  Even if the operation completes before this call, the callback won't have been
        // called.
        //
        // Returns whether the operation completed sync or not.
        private bool CaptureOrComplete(ref ExecutionContext cachedContext, bool returnContext)
        {
            GlobalLog.Assert((_flags & StateFlags.PostBlockStarted) != 0, "ContextAwareResult#{0}::CaptureOrComplete|Called without calling StartPostingAsyncOp.", Logging.HashString(this));

            // See if we're going to need to capture the context.
            bool capturingContext = AsyncCallback != null || (_flags & StateFlags.CaptureContext) != 0;

            // Peek if we've already completed, but don't fix CompletedSynchronously yet
            // Capture the identity if requested, unless we're going to capture the context anyway, unless
            // capturing the context won't be sufficient.
            if ((_flags & StateFlags.CaptureIdentity) != 0 && !InternalPeekCompleted && (!capturingContext))
            {
                GlobalLog.Print("ContextAwareResult#" + Logging.HashString(this) + "::CaptureOrComplete() starting identity capture");
                SafeCaptureIdentity();
            }

            // No need to flow if there's no callback, unless it's been specifically requested.
            // Note that Capture() can return null, for example if SuppressFlow() is in effect.
            if (capturingContext && !InternalPeekCompleted)
            {
                GlobalLog.Print("ContextAwareResult#" + Logging.HashString(this) + "::CaptureOrComplete() starting capture");
                if (cachedContext == null)
                {
                    cachedContext = ExecutionContext.Capture();
                }

                if (cachedContext != null)
                {
                    if (!returnContext)
                    {
                        _context = cachedContext;
                        cachedContext = null;
                    }
                    else
                    {
                        _context = cachedContext.CreateCopy();
                    }
                }
                GlobalLog.Print("ContextAwareResult#" + Logging.HashString(this) + "::CaptureOrComplete() _Context:" + Logging.HashString(_context));
            }
            else
            {
                // Otherwise we have to have completed synchronously, or not needed the context.
                GlobalLog.Print("ContextAwareResult#" + Logging.HashString(this) + "::CaptureOrComplete() skipping capture");
                cachedContext = null;
                GlobalLog.Assert(AsyncCallback == null || CompletedSynchronously, "ContextAwareResult#{0}::CaptureOrComplete|Didn't capture context, but didn't complete synchronously!", Logging.HashString(this));
            }

            // Now we want to see for sure what to do.  We might have just captured the context for no reason.
            // This has to be the first time the state has been queried "for real" (apart from InvokeCallback)
            // to guarantee synchronization with Complete() (otherwise, Complete() could try to call the
            // callback without the context having been gotten).
            DebugProtectState(false);
            if (CompletedSynchronously)
            {
                GlobalLog.Print("ContextAwareResult#" + Logging.HashString(this) + "::CaptureOrComplete() completing synchronously");
                base.Complete(IntPtr.Zero);
                return true;
            }

            return false;
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:67,代码来源:_ContextAwareResult.cs

示例7: WrapFlushDelegate

 static Func<Action, bool> WrapFlushDelegate(ExecutionContext context, Func<Action, bool> flush)
 {
     return drained => drained == null ? flush(null) : flush(() => ExecutionContext.Run(context.CreateCopy(), _ => drained(), null));
 }
开发者ID:markrendle,项目名称:gate,代码行数:4,代码来源:ExecutionContextPerRequest.cs

示例8: WrapWriteDelegate

 static Func<ArraySegment<byte>, Action, bool> WrapWriteDelegate(ExecutionContext context, Func<ArraySegment<byte>, Action, bool> write)
 {
     return (data, callback) => callback == null ? write(data, null) : write(data, () => ExecutionContext.Run(context.CreateCopy(), _ => callback(), null));
 }
开发者ID:ArloL,项目名称:gate,代码行数:4,代码来源:ExecutionContextPerRequest.cs


注:本文中的System.Threading.ExecutionContext.CreateCopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。