Use the application domain to cache global data

Source: Internet
Author: User

C # does not have the concept of global data, but sometimes we wantProgramIn the Web, we can use the application object to process global data. How to implement it in winform. In fact, we can use the application domain to implement it. It is an independent environment in which the application runs and is managed for execution.CodeProvides isolation, uninstallation, and security boundaries. Multiple application domains can run in one process. However, there is no one-to-one association between application domains and threads. Multiple Threads can belong to one application domain. Although the given thread is not limited to one application domain, the thread is executed in one application domain at any given time.
It seems that the code is implemented.
Using system. Threading;
Public class appdomaintest
{
Public static void main ()
{

Thread. getdomain (). setdata ("mydata", "ABC ");
Getmydata ();
}
Public static void getmydata ()
{
Console. Write (string) thread. getdomain (). getdata ("mydata "));
}
// Of course, you can also use thread. setdata,
}

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.