// Async patern

        internal /*public*/ IAsyncResult BeginAspCompatExecution(AsyncCallback cb, object extraData)
        {
            InternalSecurityPermissions.UnmanagedCode.Demand();

            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);

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

            return(_ar);
        }
Exemple #2
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);
        }