跨AppDomain通信

public class AppDomainTest : MarshalByRefObject
    {
       public string TestMethodStr(string srcAppDomain)
        {
            string TTT = "TTT";

            byte[] m_ExtraMemory = new byte[1024 * 1024 * 99];

            Console.WriteLine(
            "Code from the '{0}' AppDomain\n" +
            "called into the '{1}'. AppDomain.",
            srcAppDomain, Thread.GetDomain().FriendlyName);


            Console.WriteLine(
           "Code from the  TTT= '{0}' AppDomain\n" +
           "called into the '{1}'. AppDomain.",
           TTT, Thread.GetDomain().FriendlyName);
            return TTT;

        }
    }

static void Main(string[] args)
{

AppDomain domainArcher = AppDomain.CreateDomain("MyNewDomain", null, null);
AppDomainTest test1 = (AppDomainTest)domainArcher.CreateInstanceAndUnwrap(System.Reflection.Assembly.GetCallingAssembly().FullName, "ConsoleApp1.AppDomainTest");

var tt1 = test1.TestMethodStr(Thread.GetDomain().FriendlyName);

Console.ReadLine();

   }

 

 

进程内 AppDomain 间通信,但实测下,效率太慢了,只适合某些特殊情况下使用

 

posted @ 2019-06-28 16:39  纵一苇之所如-  阅读(294)  评论(0编辑  收藏  举报