Пример #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();
 }
Пример #2
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);
            }
        }