简体   繁体   中英

ThreadStatic for .net compact framework

如何在.net Compact Framework 3.5中重现ThradStatic行为?

我建议使用Thread.Current将由线程ID索引的静态(在这种情况下为appdomain静态)字典与相关的getter和setters thtat索引建立索引。

You can use the LocalDataStoreSlot class, that automatically discards the object when the Thread terminates.

Eg:

private static readonly LocalDataStoreSlot nameSlot = Thread.AllocateDataSlot();

public string Name
{
    get { return (string)Thread.GetData(nameSlot); }
    set { Thread.SetData(nameSlot, value); }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM