System.Threading.CancellationRegion.PollForCancellation C# (CSharp) Method

PollForCancellation() private method

private PollForCancellation ( ) : void
return void
        public static void PollForCancellation()
        {
            Thread t = Thread.CurrentThread;
            // Don't go through the property on Thread, but access the field
            // directly.  We don't want to create the stack if no one in the
            // thread is using cancellation.
            List<CancellationSignal> signals = t.m_CancellationSignals;
            if (signals != null) {
                bool tookLock = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try {
                    Monitor.ReliableEnter(signals, out tookLock);
                    if (signals.Count > 0) {
                        if (signals[signals.Count - 1].CancelRequested)
                            throw new OperationCanceledException();
                    }
                }
                finally {
                    if (tookLock)
                        Monitor.Exit(signals);
                }
            }
        }
    }