In order for a static field to have its value in each thread, it should be marked with the attribute ThreadStatic. Is there a standard mechanism to do the same with non-static fields?
2 answers
In Java, this is ThreadLocal<T>
. In 4 С # they introduced a similar construction: ThreadLocal . For earlier versions, you can look at possible solutions for SO .
|
Found the most appropriate solution: Thread.AllocateDataSlot.
Further in each copy the slot is stored, and the appeal to a variable goes through it.
|