简体   繁体   中英

Treatment of Shared in GAC Included Assemblies

I know that when creating a DLL and declaring items as "Shared" (Static in C#) that they are instantiated when first called, and then that object reference lives on as the single reference.

So declaring a shared string property once set can be called again to retreive the same value. And that thread safety is then a Major concern within the application domain.

What happens outside of the application domain. If we put the assembly in the Global Application Cache (GAC) how many instances will exist?

For example a static property called "MyFileName" in a GAC'ed .dll.

Then we have two applications calling the GAC'ed .dll. How many instances of "MyFileName" would exist? Would changes to MyFileName from Application one copy over to the value that Application Two uses?

The dll is instantiated within the AppDomain, so there are as many different copies as there are AppDomains. Data does not transfer between AppDomains. Putting the DLL in the GAC just makes it available to everything in one place, it doesn't change the memory model of .net.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM