Use the application domain to cache global data

xiaoxiao2021-03-06  42

There is no concept of global data in C #, but sometimes we want to access global data in the application. In the web, we can use the Application object to handle it. How to implement it in WinForm? In fact, we can use the application domain to implement, it is an independent environment in which an application is implemented, providing isolation, unloading, and security boundaries for executive managed code. Multiple application domains can run in a process; however, there is no one-to-one association between the application domain and the thread. Multiple threads can belong to an application domain, although the given thread is not limited to an application domain, but at any given time, the thread is executed in an application domain. It seems how 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 ( Thread.getdomain (). getData ("mydata"));} // can of course also use thread.SetData (); customization,}

转载请注明原文地址:https://www.9cbs.com/read-79017.html

New Post(0)