Amib.Threading.Internal.CallerThreadContext.Capture C# (CSharp) Méthode

Capture() public static méthode

Captures the current thread context
public static Capture ( bool captureCallContext, bool captureHttpContext ) : CallerThreadContext
captureCallContext bool
captureHttpContext bool
Résultat CallerThreadContext
        public static CallerThreadContext Capture(
			bool captureCallContext, 
			bool captureHttpContext)
        {
            Debug.Assert(captureCallContext || captureHttpContext);

            CallerThreadContext callerThreadContext = new CallerThreadContext();

            // TODO: In NET 2.0, redo using the new feature of ExecutionContext class - Capture()
            // Capture Call Context
            if(captureCallContext && (getLogicalCallContextMethodInfo != null))
            {
                callerThreadContext._callContext = (LogicalCallContext)getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null);
                if (callerThreadContext._callContext != null)
                {
                    callerThreadContext._callContext = (LogicalCallContext)callerThreadContext._callContext.Clone();
                }
            }

            // Capture httpContext
            if (captureHttpContext && (null != HttpContext.Current))
            {
                callerThreadContext._httpContext = HttpContext.Current;
            }

            return callerThreadContext;
        }

Usage Example

Exemple #1
0
        /// <summary>
        ///   Execute the work item
        /// </summary>
        private void ExecuteWorkItem()
        {
            CallerThreadContext ctc = null;

            if (null != _callerContext)
            {
                ctc = CallerThreadContext.Capture(_callerContext.CapturedCallContext, _callerContext.CapturedHttpContext);
                CallerThreadContext.Apply(_callerContext);
            }

            Exception exception = null;
            object    result    = null;

            try
            {
                result = _callback(_state);
            }
            catch (Exception e)
            {
                // Save the exception so we can rethrow it later
                exception = e;
            }

            if (null != _callerContext)
            {
                CallerThreadContext.Apply(ctc);
            }

            SetResult(result, exception);
        }
All Usage Examples Of Amib.Threading.Internal.CallerThreadContext::Capture