コード例 #1
0
        internal void BeginWorker(ReferralQueue.State stateParam)
        {
            this.WaitForEvent(this.workerAvailableEvent);
            if (!this.ShouldCreateWorkerThread())
            {
                try
                {
                    stateParam.WorkerMethod(stateParam.WorkerState);
                    return;
                }
                finally
                {
                    this.pendingAuthorities.Remove(stateParam.AuthorityKey);
                    this.UpdateOnQueueChange();
                }
            }
            this.currentWorkerCount++;
            ReferralQueue.UpdateEvent(this.workerAvailableEvent, this.IsWorkerAvailable);
            bool flag = true;

            try
            {
                TrackingEventBudget.AcquireThread();
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    TrackingEventBudget.ReleaseThread();
                }
            }
            ThreadPool.QueueUserWorkItem(new WaitCallback(this.WorkerMethodWrapper), stateParam);
        }
コード例 #2
0
        private void WorkerMethodWrapper(object stateObject)
        {
            ReferralQueue.State state   = (ReferralQueue.State)stateObject;
            bool          flag          = false;
            bool          flag2         = false;
            TrackingError trackingError = null;

            try
            {
                this.directoryContext.Acquire();
                flag = true;
                if (this.directoryContext.DiagnosticsContext.DiagnosticsLevel == DiagnosticsLevel.Etw)
                {
                    CommonDiagnosticsLogTracer traceWriter = new CommonDiagnosticsLogTracer();
                    TraceWrapper.SearchLibraryTracer.Register(traceWriter);
                    flag2 = true;
                }
                state.WorkerMethod(state.WorkerState);
            }
            catch (TrackingTransientException ex)
            {
                if (!ex.IsAlreadyLogged)
                {
                    trackingError = ex.TrackingError;
                }
            }
            catch (TrackingFatalException ex2)
            {
                if (ex2.IsAlreadyLogged)
                {
                    trackingError = ex2.TrackingError;
                }
            }
            catch (TransientException ex3)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorTransient, string.Empty, ex3.Message, ex3.ToString());
            }
            catch (DataSourceOperationException ex4)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, string.Empty, "Error from Active Directory provider", ex4.ToString());
            }
            catch (DataValidationException ex5)
            {
                trackingError = new TrackingError(ErrorCode.UnexpectedErrorPermanent, string.Empty, "Validation Error from Active Directory provider", ex5.ToString());
            }
            finally
            {
                if (flag)
                {
                    if (trackingError != null)
                    {
                        TraceWrapper.SearchLibraryTracer.TraceError <TrackingError>(this.GetHashCode(), "Error in woker thread while processing referral, {0}", trackingError);
                        this.directoryContext.Errors.Errors.Add(trackingError);
                    }
                    this.pendingAuthorities.Remove(state.AuthorityKey);
                    this.currentWorkerCount--;
                    ReferralQueue.UpdateEvent(this.workerAvailableEvent, this.IsWorkerAvailable);
                    this.UpdateOnQueueChange();
                    if (flag2)
                    {
                        TraceWrapper.SearchLibraryTracer.Unregister();
                    }
                    this.directoryContext.Yield();
                    TrackingEventBudget.ReleaseThread();
                }
            }
        }