How best to communicate between AppDomains?

前端 未结 6 1865
孤城傲影
孤城傲影 2020-12-07 22:31

I have an application that needs to send a moderately high volume of messages between a number of AppDomains. I know that I could implement this using remoting, but I have

6条回答
  •  [愿得一人]
    2020-12-07 23:16

    I just discovered that you may also use the AppDomain.SetData but this is only one way From Host Domain to Child Domain.

    static void RunInChildDomain()
    {
         AppDomain childDomain = AppDomain.CreateDomain("friendlyName");
         string parameterValue = "notmii";
         childDomain.SetData("parameter", parameterValue);
         childDomain.DoCallBack(PrintName);
    }
    
    static void PrintName()
    {
         string Name = Convert.ToString(AppDomain.CurrentDomain.GetData("parameter"));
         Console.WriteLine(Name);
    }
    

    You can also create exception driven communication between child and host appdomain by using AppDomain.FirstChanceException event :)

提交回复
热议问题