Thread data slot

Source: Internet
Author: User
Thread Local data slot public static cscontext current
{
Get
{
Localdatastoreslot storeslot = getslot ();
Cscontext context = thread. getdata (storeslot) as cscontext;
If (context = NULL)
{
Httpcontext = httpcontext. Current;
If (httpcontext = NULL)
Throw new exception ("No cscontext exists in the current application. autocreate fails since httpcontext. Current is not accessible ");

Context = new cscontext (httpcontext );
Savecontexttostore (storeslot, context );
}
Return context;
}
}


After reading the above code, I know that the thread has a concept of a local data slot. What is the function of this item? Is it used in a single thread or multiple threads?

Related Articles:

Local thread storage (TLS)
Steps for storing local storage:
1. Apply for a data slot

Localdatastoreslot slot = thread. getnameddataslot ("para ");


If the data slot named para does not exist, a para data slot that can be used by all threads will be allocated.
2. store data in the data slot

Mypara para = new mypara ();
Para. I = I;
Thread. setdata (slot, para );


3. Release the data slot if necessary

Thread. freenameddataslot ("para ");


Be careful when releasing the data slot. This operation will cause data loss in all threads stored in the released data slot.

Steps for reading local storage:
1. Obtain specific data slots in local storage of sub-threads based on their names

Localdatastoreslot slot = thread. getnameddataslot ("para ");

2. obtain data from the data slot

Object o = thread. getdata (slot );
If (o! = NULL)
{
// Convert to a specific type
Mypara para = (mypara) O;
//.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.