示例#1
0
        public override void Cancel()
        {
            unchecked
            { _changeID++; }

            UnsafeNativeMethods.ICommandText icmdtxt = _icommandText;
            if (null != icmdtxt)
            {
                OleDbHResult hr = OleDbHResult.S_OK;

                lock (icmdtxt)
                {
                    // lock the object to avoid race conditions between using the object and releasing the object
                    // after we acquire the lock, if the class has moved on don't actually call Cancel
                    if (icmdtxt == _icommandText)
                    {
                        hr = icmdtxt.Cancel();
                    }
                }
                if (OleDbHResult.DB_E_CANTCANCEL != hr)
                {
                    // if the provider can't cancel the command - don't cancel the DataReader
                    this.canceling = true;
                }

                // since cancel is allowed to occur at anytime we can't check the connection status
                // since if it returns as closed then the connection will close causing the reader to close
                // and that would introduce the possilbility of one thread reading and one thread closing at the same time
                ProcessResultsNoReset(hr);
            }
            else
            {
                this.canceling = true;
            }
        }
        public override void Cancel()
        {
            IntPtr ptr;

            Bid.ScopeEnter(out ptr, "<oledb.OleDbCommand.Cancel|API> %d#\n", this.ObjectID);
            try
            {
                this._changeID++;
                UnsafeNativeMethods.ICommandText text = this._icommandText;
                if (text != null)
                {
                    OleDbHResult result = OleDbHResult.S_OK;
                    lock (text)
                    {
                        if (text == this._icommandText)
                        {
                            Bid.Trace("<oledb.ICommandText.Cancel|API|OLEDB> %d#\n", this.ObjectID);
                            result = text.Cancel();
                            Bid.Trace("<oledb.ICommandText.Cancel|API|OLEDB|RET> %08X{HRESULT}\n", result);
                        }
                    }
                    if (OleDbHResult.DB_E_CANTCANCEL != result)
                    {
                        this.canceling = true;
                    }
                    this.ProcessResultsNoReset(result);
                }
                else
                {
                    this.canceling = true;
                }
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
        }