Thread storage

Thread-relative static fields and data slots are the two ways in which we can store data that is unique to the thread and application domain. Thread-relative static fields are defined at compile time and provide the best performance. Another benefit is that they do compile-time type checking. These fields are used when the requirement about what kind of data to be stored is clear beforehand.

Thread-relative static fields can be created using ThreadStaticAttribute.

There are scenarios where these storage requirements may arise at runtime. In such scenarios, we can opt for data slots. These are a bit slower than static fields. Since these are created at runtime, they store information as an object type. It is important for ...

Get Programming in C#: Exam 70-483 (MCSD) Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.