Example #1
0
        private bool MoveNext(bool discardResultsAndErrors)
        {
            T              t              = null;
            MiResult       miResult       = MiResult.OK;
            string         str            = null;
            InstanceHandle instanceHandle = null;
            bool           flag;

            if (!discardResultsAndErrors)
            {
                lock (this._internalErrorWhileProcessingAsyncCallbackLock)
                {
                    if (this._internalErrorWhileProcessingAsyncCallback != null)
                    {
                        throw this._internalErrorWhileProcessingAsyncCallback;
                    }
                }
            }
            if (this._moreResultsAreExpected)
            {
                this.AssertNotDisposed();
                MiResult miResult1 = this.NativeMoveNext(base.Operation.Handle, out t, out this._moreResultsAreExpected, out miResult, out str, out instanceHandle);
                CimException.ThrowIfMiResultFailure(miResult1);
                if (!this._moreResultsAreExpected)
                {
                    base.Operation.IgnoreSubsequentCancellationRequests();
                }
                if (!discardResultsAndErrors)
                {
                    lock (this._internalErrorWhileProcessingAsyncCallbackLock)
                    {
                        if (this._internalErrorWhileProcessingAsyncCallback != null)
                        {
                            throw this._internalErrorWhileProcessingAsyncCallback;
                        }
                    }
                    CimException exceptionIfMiResultFailure = CimException.GetExceptionIfMiResultFailure(miResult, str, instanceHandle);
                    if (exceptionIfMiResultFailure == null)
                    {
                        this.DisposeCurrentItemIfNeeded();
                        this.Current = t;
                    }
                    else
                    {
                        CancellationMode cancellationMode = base.Operation.CancellationMode;
                        if (cancellationMode != CancellationMode.ThrowOperationCancelledException)
                        {
                            throw exceptionIfMiResultFailure;
                        }
                        else
                        {
                            throw new OperationCanceledException(exceptionIfMiResultFailure.Message, exceptionIfMiResultFailure);
                        }
                    }
                }
                else
                {
                    IDisposable disposable = (object)t as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                        t = default(T);
                    }
                    if (instanceHandle != null)
                    {
                        instanceHandle.Dispose();
                    }
                }
                if (t == null)
                {
                    flag = this._moreResultsAreExpected;
                }
                else
                {
                    flag = true;
                }
                return(flag);
            }
            else
            {
                return(false);
            }
        }