System.Threading.TimerBase.ChangeTimer C# (CSharp) Method

ChangeTimer() private method

private ChangeTimer ( UInt32 dueTime, UInt32 period ) : bool
dueTime System.UInt32
period System.UInt32
return bool
        internal bool ChangeTimer(UInt32 dueTime,UInt32 period)
        {
            bool status = false;
            bool bLockTaken = false;

            // prepare here to prevent threadabort from occuring which could
            // destroy m_lock state.  lock(this) can't be used due to critical
            // finalizer and thinlock/syncblock escalation.
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                do 
                {
                    if (Interlocked.CompareExchange(ref m_lock, 1, 0) == 0)
                    {
                        bLockTaken = true;
                        try
                        {
                            if (timerDeleted != 0)
                                throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic"));
                            status = ChangeTimerNative(dueTime,period);
                        }
                        finally
                        {
                            m_lock = 0;
                        }
                    }
                    Thread.SpinWait(1);     // yield to processor
                }
                while (!bLockTaken);
            }
            return status;

        }

Usage Example

コード例 #1
0
        public bool Change(int dueTime, int period)
        {
            if (dueTime < -1)
            {
                throw new ArgumentOutOfRangeException("dueTime", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
            }
            if (period < -1)
            {
                throw new ArgumentOutOfRangeException("period", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
            }

            return(timerBase.ChangeTimer((UInt32)dueTime, (UInt32)period));
        }