简体   繁体   English

GAC包含的程序集中共享的处理

[英]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. 我知道在创建DLL并将项目声明为“ Shared”(C#中的静态)时,它们在首次调用时便被实例化,然后该对象引用作为单个引用存在。

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? 如果将程序集放在全局应用程序缓存(GAC)中,将存在多少个实例?

For example a static property called "MyFileName" in a GAC'ed .dll. 例如,GAC编辑的.dll中的静态属性“ MyFileName”。

Then we have two applications calling the GAC'ed .dll. 然后,我们有两个应用程序称为GAC'ed .dll。 How many instances of "MyFileName" would exist? 将存在多少个“ MyFileName”实例? Would changes to MyFileName from Application one copy over to the value that Application Two uses? 将MyFileName从应用程序一更改为应用程序二使用的值吗?

The dll is instantiated within the AppDomain, so there are as many different copies as there are AppDomains. dll是在AppDomain中实例化的,因此,与AppDomains一样,副本数量也一样多。 Data does not transfer between AppDomains. 数据不会在AppDomain之间传输。 Putting the DLL in the GAC just makes it available to everything in one place, it doesn't change the memory model of .net. 将DLL放入GAC只是使它可以在一处对所有内容使用,而不会更改.net的内存模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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