首页 > 开发 > 综合 > 正文

在指定应用程序域中执行代码

2024-07-21 02:28:53
字体:
来源:转载
供稿:网友

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


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();
        }
    }
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表