예제 #1
0
        internal /*public*/ IAsyncResult BeginAspCompatExecution(AsyncCallback cb, object extraData)
        {
            SynchronizationContextUtil.ValidateModeForAspCompat();

            if (IsInAspCompatMode)
            {
                // already in AspCompatMode -- execute synchronously
                bool      sync  = true;
                Exception error = _app.ExecuteStep(this, ref sync);
                _ar         = new HttpAsyncResult(cb, extraData, true, null, error);
                _syncCaller = true;
            }
            else
            {
                _ar         = new HttpAsyncResult(cb, extraData);
                _syncCaller = (cb == null);
                _rootedThis = GCHandle.Alloc(this);

                // send requests from the same session to the same STA thread
                bool sharedActivity = (_sessionId != null);
                int  activityHash   = sharedActivity ? _sessionId.GetHashCode() : 0;

                if (UnsafeNativeMethods.AspCompatProcessRequest(_execCallback, this, sharedActivity, activityHash) != 1)
                {
                    // failed to queue up the execution in ASP compat mode
                    _rootedThis.Free();
                    _ar.Complete(true, null, new HttpException(SR.GetString(SR.Cannot_access_AspCompat)));
                }
            }

            return(_ar);
        }
예제 #2
0
        // IExecutionStep implementation

        void HttpApplication.IExecutionStep.Execute()
        {
            SynchronizationContextUtil.ValidateModeForAspCompat();

            if (_code != null)
            {
                _code();
            }
            else if (_codeEventHandler != null)
            {
                _codeEventHandler(_codeEventSource, _codeEventArgs);
            }
        }