首页 | IT新闻 | 硬件 | 操作系统 | 开发 | 网络编程 | 数据库 | 热门框架 | 网络安全 | 组网 | 建站指南 | 网页制作 | 特效 | 实用技巧 | 服务器 | 办公 | QQ | 探索 | 社区

  • 技术部落
  • 部落首页 > 程序开发 > C/C#/C++ > 正文
  • 在指定应用程序域中执行代码
      2007-2-25  来源:网络资源  编辑:Jsbulo  热度:

    超级入门级:) 哈哈~ 留个纪念。
    //
    // 在指定应用程序域中执行代码
    //
    //
    //


    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace DomainTest
    {
        class Program
        {
            private static string strKey = "Key1";

            static void Main(string[] args)
            {
                AppDomain domaintest = AppDomain.CreateDomain("Domaintest");
                string strVal = "Value1";
                domaintest.SetData(strKey, strVal);

                // 跨程序域调用委托
                CrossAppDomainDelegate callback = delegate
                {
                    // 取得当前程序域
                    AppDomain domain = AppDomain.CurrentDomain;
                    Console.WriteLine(string.Format("Value: {0} In {1}", domain.GetData(strKey), domain.FriendlyName));
                };

                // 在指定程序域中执行代码
                domaintest.DoCallBack(callback);

                Console.Read();
            }
        }
    }