Beispiel #1
0
        private void UpdateState(ThreadPoolWorkItemState newState)
        {
#if DEBUG
            SpinWait sw       = new SpinWait();
            int      curState = Volatile.Read(ref _state);
            while (IsValidStateTransition(newState, (ThreadPoolWorkItemState)curState))
            {
                if (Interlocked.CompareExchange(ref _state, (int)newState, curState) == curState)
                {
                    return;
                }

                sw.SpinOnce();
                curState = Volatile.Read(ref _state);
            }

            throw new WrongStateException("Not allowed ThreadPoolWorkItem state change from '" + ((ThreadPoolWorkItemState)curState).ToString() + "' to '" + newState.ToString() + "'");
#endif
        }