ANHAdmin.AsyncOperation.CancelAndWait C# (CSharp) Method

CancelAndWait() public method

Attempt to cancel the current operation and block until either the cancellation succeeds or the operation completes.
public CancelAndWait ( ) : bool
return bool
        public bool CancelAndWait()
        {
            lock (this)
            {
                // Set the cancelled flag

                cancelledFlag = true;

                // Now sit and wait either for the operation to
                // complete or the cancellation to be acknowledged.
                // (Wake up and check every second - shouldn't be
                // necessary, but it guarantees we won't deadlock
                // if for some reason the Pulse gets lost - means
                // we don't have to worry so much about bizarre
                // race conditions.)
                while (!IsDone)
                {
                    Monitor.Wait(this, 1000);
                }
            }
            return !HasCompleted;
        }