Amib.Threading.Internal.CallerThreadContext.Apply C# (CSharp) Method

Apply() public static method

Applies the thread context stored earlier
public static Apply ( CallerThreadContext callerThreadContext ) : void
callerThreadContext CallerThreadContext
return void
        public static void Apply(CallerThreadContext callerThreadContext)
        {
            if (null == callerThreadContext)
            {
                throw new ArgumentNullException("callerThreadContext");
            }

            // Todo: In NET 2.0, redo using the new feature of ExecutionContext class - Run()
            // Restore call context
            if ((callerThreadContext._callContext != null) && (setLogicalCallContextMethodInfo != null))
            {
                setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[] { callerThreadContext._callContext });
            }

            // Restore HttpContext
            if (callerThreadContext._httpContext != null)
            {
                HttpContext.Current = callerThreadContext._httpContext;
                //CallContext.SetData(HttpContextSlotName, callerThreadContext._httpContext);
            }
        }

Usage Example

Ejemplo n.º 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::Apply