惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
博客园 - 三生石上(FineUI控件)
博客园_首页
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网
GbyAI
GbyAI
M
MIT News - Artificial intelligence
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
Recent Announcements
Recent Announcements
小众软件
小众软件
量子位
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏

博客园 - YFeng_Lee

webHttpBinding+wsHttpBinding+basicHttpBinding的区别 (转) AppDomain 详解(转) .net工具 InstallShield12 添加自定义对话框,并根据输入值修改对应的Config文件。 普通管理类程序开发之难度系数、层次之说法(转自csdn) 待阅读书目 C#开发Windows Service程序 创建一个windows service应用程序 Ext简介(转) Ext的组件结构分析(转) XML与数据库 分析模式 - 责任模式 NHibernate Cascades: the different between all, all-delete-orphans and save-update 企业开发框架NHibernate和Spring.Net简介-4 企业开发框架NHibernate和Spring.Net简介-3 企业开发框架NHibernate和Spring.Net简介-2 企业开发框架NHibernate和Spring.Net简介-1 Nhibernate学习之many-to-many篇(转 明了篇) Nhibernate学习起步之many-to-one篇(转 明了篇)
AppDomain对于静态对象的独享引用
YFeng_Lee · 2016-12-27 · via 博客园 - YFeng_Lee

AppDomain可以理解为一个独立的沙箱,当有独立的第静态对象在appDomain中被访问时,会在appDomain中产生独立的内存对象。比如appDomain1 appDomain2同时对 静态对象A有引用时,appDomain1.A与appDomain2.A是两个对象。

 1.

静态对象属性

public class StaticModel
{
public static int IndexTest;
}

2. 

public class myClass
{
public int index;
public void Invoke()
{
    using (TestProctectedCodeInvoke tc = new TestProctectedCodeInvoke())
    {
         LogHelper.Log("index:" + index + "----------Invoke thread .id:" + Thread.CurrentThread.ManagedThreadId, "ddd", 111);
         string saa = tc.test();
         Console.WriteLine(saa);
    }
}
}
public static void Main(string[] args)
        {

            LogHelper.Log("Main start", "ffffffffff", 111);
            int i = 0;
            try
            {
                while (i < 11)
                {
                    i++;
                    myClass mc = new myClass();
                    mc.index = i;
                    LogHelper.Log("Main thread index:  【" + i + "", "ffffffffff", 111);
                    Thread t = new Thread(mc.Invoke);
                    t.Start();
                    Thread.Sleep(100);
                    Console.WriteLine(i);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            LogHelper.Log("Main end", "ffffffffff", 111);
            Console.ReadLine();
        }
class TestProctectedCodeInvoke: IDisposable
    {
        public string test()
        {
            string dllpath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory + "ClassLibrary1.dll");
            AssemblyDomain ad = new AssemblyDomain();
            object s = ad.Invoke(dllpath, "ClassLibrary1.Class1", "GetName");
            return s.ToString();
        }

        public void Dispose()
        {
            Console.WriteLine("Dispose");
        }
        ~TestProctectedCodeInvoke()
        {
            Console.WriteLine("TestProctectedCodeInvoke .xigou");
        }
    }

3. 输出结果

证明 StaticModel.IndexTest 是在各个domain中是独立的存在