可以用AppDomain类的SetData()和Getdata方法直接在AppDomain中存储数据,下面的例子演示了数据存取的过程,AppDomain中保存的数据是用特征字符串来索引的。

 

例:

 

using System;

using System.Threading;

public class Program

{

          public static void Main(){

                       AppDomain newDomain =AppDomain.CreateDomain("NewDomain");

                      CrossAppDomainDelegate deleg = new CrossAppDomainDelegate(Fct);

                      newDomain.DoCallBack(deleg);

                      int anInteger = (int) newDomain.GetData("AnInteger");

                      AppDomain.Unload(newDomain);

                    }

           public static void Fct()

            {

                      AppDomain.CurrentDomain.SetData("AnInteger",691);

            }

}

 

这个例子演示的是一个简单的情形,我们存储一个整形数据,而整形是每个AppDomain都能识别的。