System.LocalDataStore.SetData C# (CSharp) Method

SetData() public method

public SetData ( LocalDataStoreSlot slot, Object data ) : void
slot LocalDataStoreSlot
data Object
return void
        public void SetData(LocalDataStoreSlot slot, Object data)
        {
            // Validate the slot.
            m_Manager.ValidateSlot(slot);

            // I can't think of a way to avoid the race described in the
            // LocalDataStoreSlot finalizer method without a lock.
            bool tookLock = false;
            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                Monitor.ReliableEnter(m_Manager, ref tookLock);
                if (!slot.IsValid())
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_SlotHasBeenFreed"));

                // Do the actual set operation.
                SetDataInternal(slot.Slot, data, true /*bAlloc*/ );
            }
            finally {
                if (tookLock)
                    Monitor.Exit(m_Manager);
            }

        }