当前位置:首页>>网络编程>>C#教程>>正文

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

文章出处:网络转载 作者:未知 发布时间:2006-07-28 浏览次数:88
超级入门级:) 哈哈~ 留个纪念。
//
// 在指定应用程序域中执行代码
//
//
//


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

http://luoboqingcai.cnblogs.com/archive/2006/06/26/435596.html


Google