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,
}