Beispiel #1
0
 public WorkItem(IWorkItemsGroup workItemsGroup, WorkItemInfo workItemInfo, WorkItemCallback callback, object state)
 {
     this._workItemsGroup = workItemsGroup;
     this._workItemInfo   = workItemInfo;
     if (this._workItemInfo.UseCallerCallContext || this._workItemInfo.UseCallerHttpContext)
     {
         this._callerContext = CallerThreadContext.Capture(this._workItemInfo.UseCallerCallContext, this._workItemInfo.UseCallerHttpContext);
     }
     this._callback       = callback;
     this._state          = state;
     this._workItemResult = new WorkItem.WorkItemResult(this);
     this.Initialize();
 }
Beispiel #2
0
 public static void Apply(CallerThreadContext callerThreadContext)
 {
     if (callerThreadContext == null)
     {
         throw new ArgumentNullException("callerThreadContext");
     }
     if (callerThreadContext._callContext != null && CallerThreadContext.setLogicalCallContextMethodInfo != null)
     {
         CallerThreadContext.setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[]
         {
             callerThreadContext._callContext
         });
     }
     if (callerThreadContext._httpContext != null)
     {
         HttpContext.Current = callerThreadContext._httpContext;
     }
 }
Beispiel #3
0
        public static CallerThreadContext Capture(bool captureCallContext, bool captureHttpContext)
        {
            CallerThreadContext callerThreadContext = new CallerThreadContext();

            if (captureCallContext && CallerThreadContext.getLogicalCallContextMethodInfo != null)
            {
                callerThreadContext._callContext = (LogicalCallContext)CallerThreadContext.getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null);
                if (callerThreadContext._callContext != null)
                {
                    callerThreadContext._callContext = (LogicalCallContext)callerThreadContext._callContext.Clone();
                }
            }
            if (captureHttpContext && HttpContext.Current != null)
            {
                callerThreadContext._httpContext = HttpContext.Current;
            }
            return(callerThreadContext);
        }
Beispiel #4
0
        private void ExecuteWorkItem()
        {
            CallerThreadContext callerThreadContext = null;

            if (this._callerContext != null)
            {
                callerThreadContext = CallerThreadContext.Capture(this._callerContext.CapturedCallContext, this._callerContext.CapturedHttpContext);
                CallerThreadContext.Apply(this._callerContext);
            }
            Exception exception = null;
            object    result    = null;

            try
            {
                try
                {
                    result = this._callback(this._state);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }
                if (Interlocked.CompareExchange <Thread>(ref this._executingThread, null, this._executingThread) == null)
                {
                    Thread.Sleep(60000);
                }
            }
            catch (ThreadAbortException)
            {
                if (!SmartThreadPool.CurrentThreadEntry.AssociatedSmartThreadPool.IsShuttingdown)
                {
                    Thread.ResetAbort();
                }
            }
            if (this._callerContext != null)
            {
                CallerThreadContext.Apply(callerThreadContext);
            }
            if (!SmartThreadPool.IsWorkItemCanceled)
            {
                this.SetResult(result, exception);
            }
        }