示例#1
0
 private void ResumeTasks(bool waitUntilDone, bool onCallerThread)
 {
     Interlocked.Increment(ref this._tasksStarted);
     try
     {
         if (onCallerThread)
         {
             this.ResumeTasksPossiblyUnderLock(waitUntilDone);
         }
         else
         {
             lock (this._app)
             {
                 HttpApplication.ThreadContext context = null;
                 try
                 {
                     context = this._app.OnThreadEnter();
                     this.ResumeTasksPossiblyUnderLock(waitUntilDone);
                 }
                 finally
                 {
                     if (context != null)
                     {
                         context.Leave();
                     }
                 }
             }
         }
     }
     finally
     {
         this.TaskCompleted(onCallerThread);
     }
 }
示例#2
0
 private void ExecuteAspCompatCode()
 {
     this.MarkCallContext(this);
     try
     {
         bool completedSynchronously = true;
         if (this._context != null)
         {
             HttpApplication.ThreadContext context = null;
             try
             {
                 context     = this._app.OnThreadEnter();
                 this._error = this._app.ExecuteStep(this, ref completedSynchronously);
                 return;
             }
             finally
             {
                 if (context != null)
                 {
                     context.Leave();
                 }
             }
         }
         this._error = this._app.ExecuteStep(this, ref completedSynchronously);
     }
     finally
     {
         this.MarkCallContext(null);
     }
 }
 private void CallCallbackPossiblyUnderLock(SendOrPostCallback callback, object state)
 {
     HttpApplication.ThreadContext context = null;
     try
     {
         context = this._application.OnThreadEnter();
         try
         {
             callback(state);
         }
         catch (Exception exception)
         {
             this._error = exception;
         }
     }
     finally
     {
         if (context != null)
         {
             context.Leave();
         }
     }
 }
        private void CompleteTask(bool timedOut, bool syncTimeoutCaller)
        {
            bool flag;

            if (Interlocked.Exchange(ref this._completionMethodLock, 1) != 0)
            {
                return;
            }
            bool flag2 = false;

            if (timedOut)
            {
                flag = !syncTimeoutCaller;
            }
            else
            {
                this._completedSynchronously = this._asyncResult.CompletedSynchronously;
                flag = !this._completedSynchronously;
            }
            HttpApplication application = this._taskManager.Application;

            try
            {
                if (flag)
                {
                    lock (application)
                    {
                        HttpApplication.ThreadContext context = null;
                        try
                        {
                            context = application.OnThreadEnter();
                            if (timedOut)
                            {
                                if (this._timeoutHandler != null)
                                {
                                    this._timeoutHandler(this._asyncResult);
                                }
                            }
                            else
                            {
                                this._endHandler(this._asyncResult);
                            }
                        }
                        finally
                        {
                            if (context != null)
                            {
                                context.Leave();
                            }
                        }
                        goto Label_0141;
                    }
                }
                if (timedOut)
                {
                    if (this._timeoutHandler != null)
                    {
                        this._timeoutHandler(this._asyncResult);
                    }
                }
                else
                {
                    this._endHandler(this._asyncResult);
                }
            }
            catch (ThreadAbortException exception)
            {
                this._error = exception;
                HttpApplication.CancelModuleException exceptionState = exception.ExceptionState as HttpApplication.CancelModuleException;
                if ((exceptionState != null) && !exceptionState.Timeout)
                {
                    lock (application)
                    {
                        if (!application.IsRequestCompleted)
                        {
                            flag2 = true;
                            application.CompleteRequest();
                        }
                    }
                    this._error = null;
                }
                Thread.ResetAbort();
            }
            catch (Exception exception3)
            {
                this._error = exception3;
            }
Label_0141:
            this._completed = true;
            this._taskManager.TaskCompleted(this._completedSynchronously);
            if (flag2)
            {
                this._taskManager.CompleteAllTasksNow(false);
            }
        }
        internal static int ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, int flags)
        {
            IIS7WorkerRequest         wr                 = null;
            HttpContext               context            = null;
            RequestNotificationStatus notificationStatus = RequestNotificationStatus.Continue;

            if (managedHttpContext == IntPtr.Zero)
            {
                InitializeRequestContext(nativeRequestContext, flags, out wr, out context);
                if (context == null)
                {
                    return(2);
                }
                context.Root();
                UnsafeIISMethods.MgdSetManagedHttpContext(nativeRequestContext, context.ContextPtr);
                HttpRuntime.IncrementActivePipelineCount();
            }
            else
            {
                context = UnwrapContext(managedHttpContext);
                wr      = context.WorkerRequest as IIS7WorkerRequest;
            }
            if ((context.InIndicateCompletion && (context.CurrentThread != Thread.CurrentThread)) && (0x20000000 != UnsafeIISMethods.MgdGetCurrentNotification(nativeRequestContext)))
            {
                while (context.InIndicateCompletion)
                {
                    Thread.Sleep(10);
                }
            }
            NotificationContext notificationContext = context.NotificationContext;
            bool locked = false;

            try
            {
                bool isReEntry = notificationContext != null;
                if (isReEntry)
                {
                    context.ApplicationInstance.AcquireNotifcationContextLock(ref locked);
                }
                context.NotificationContext = new NotificationContext(flags, isReEntry);
                notificationStatus          = HttpRuntime.ProcessRequestNotification(wr, context);
            }
            finally
            {
                if (notificationStatus != RequestNotificationStatus.Pending)
                {
                    context.NotificationContext = notificationContext;
                }
                if (locked)
                {
                    context.ApplicationInstance.ReleaseNotifcationContextLock();
                }
            }
            if (notificationStatus != RequestNotificationStatus.Pending)
            {
                HttpApplication.ThreadContext indicateCompletionContext = context.IndicateCompletionContext;
                if (!context.InIndicateCompletion && (indicateCompletionContext != null))
                {
                    if (notificationStatus == RequestNotificationStatus.Continue)
                    {
                        try
                        {
                            context.InIndicateCompletion = true;
                            Interlocked.Increment(ref _inIndicateCompletionCount);
                            UnsafeIISMethods.MgdIndicateCompletion(nativeRequestContext, ref notificationStatus);
                            goto Label_01C2;
                        }
                        finally
                        {
                            Interlocked.Decrement(ref _inIndicateCompletionCount);
                            if (!indicateCompletionContext.HasLeaveBeenCalled)
                            {
                                lock (indicateCompletionContext)
                                {
                                    if (!indicateCompletionContext.HasLeaveBeenCalled)
                                    {
                                        indicateCompletionContext.Leave();
                                        context.IndicateCompletionContext = null;
                                        context.InIndicateCompletion      = false;
                                    }
                                }
                            }
                        }
                    }
                    if (!indicateCompletionContext.HasLeaveBeenCalled)
                    {
                        lock (indicateCompletionContext)
                        {
                            if (!indicateCompletionContext.HasLeaveBeenCalled)
                            {
                                indicateCompletionContext.Leave();
                                context.IndicateCompletionContext = null;
                                context.InIndicateCompletion      = false;
                            }
                        }
                    }
                }
            }
Label_01C2:
            return((int)notificationStatus);
        }