Home Contact RSS

Thread Üzerinde Obje Saklama

System.Threading.Thread class’ı üzerinde bulunan method’ların yardımı ile ilgili Thread üzerinde memory slot’ları oluÅŸturup, içlerinde istediÄŸiniz bilgiyi saklayabilirsiniz.

Çok basit bir örneğini aşağıda ekliyorum.

using System.Threading;

public class SlotDataProvider
{
    public static object GetFromSlot(string slotName)
    {
        LocalDataStoreSlot slot = GetSlot(slotName);

        if (slot == null)
            return null;

        return Thread.GetData(slot);
    }

    private static void SaveToSlot(string slotName, object data)
    {
        LocalDataStoreSlot slot = GetSlot(slotName);

        if (slot == null)
            return;

        Thread.SetData(slot, data);
    }

    private static LocalDataStoreSlot GetSlot(string slotName)
    {
        return Thread.GetNamedDataSlot(slotName);
    }
}

Leave a Comment