using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text; namespace SGSMWebTest
{
public partial class Default : System.Web.UI.Page
{
private static FirstEliteValidateLib.Validator MyValidator = null; protected void Page_Load(object sender, EventArgs e)
{
var sb = new StringBuilder();
_AppDomain defaultAppDomain;
var appdomainList = CLRUtil.EnumAppDomains(out defaultAppDomain).ToList();
sb.AppendLine("***********Start**************"); foreach (var appdomain in appdomainList)
sb.AppendLine("AppDomainName:" + appdomain.FriendlyName + (appdomain.FriendlyName == defaultAppDomain.FriendlyName ? " [DefaultAppDomain]" : string.Empty)); sb.AppendLine("***********End**************");
sb.AppendLine("Current Appdomain:" + AppDomain.CurrentDomain.FriendlyName); if (defaultAppDomain.GetData("Validator") == null)
{
MyValidator = new FirstEliteValidateLib.Validator();
defaultAppDomain.SetData("Validator", MyValidator);
sb.AppendLine("Set Validator");
}
else
{
MyValidator = defaultAppDomain.GetData("Validator") as FirstEliteValidateLib.Validator;
if(MyValidator != null)
sb.AppendLine("Validator Get Success");
else
sb.AppendLine("Validator Get null");
} Label1.Text = "<pre>" + sb.ToString() + "</pre>";
} public static class CLRUtil
{
public static List<_AppDomain> EnumAppDomains(out _AppDomain defaultAppDomain)
{
// Obtain ICLRMetaHost interface
object objHost;
int hr = CLRCreateInstance(ref CLSID_CLRMetaHost, ref IID_CLRMetaHost, out objHost);
if (hr < ) throw new COMException("Cannot create meta host", hr);
var host = (ICLRMetaHost)objHost; // Obtain ICLRRuntimeInfo interface
var vers = Environment.Version;
var versString = string.Format("v{0}.{1}.{2}", vers.Major, vers.Minor, vers.Build);
var objRuntime = host.GetRuntime(versString, ref IID_CLRRuntimeInfo);
var runtime = (ICLRRuntimeInfo)objRuntime;
bool started;
uint flags;
runtime.IsStarted(out started, out flags);
if (!started) throw new COMException("CLR not started??"); // Obtain legacy ICorRuntimeHost interface and iterate appdomains
var result = new List<_AppDomain>();
var V2Host = (ICorRuntimeHost)runtime.GetInterface(ref CLSID_CorRuntimeHost, ref IID_CorRuntimeHost);
V2Host.GetDefaultDomain(out defaultAppDomain);
IntPtr hDomainEnum;
V2Host.EnumDomains(out hDomainEnum);
for (; ; )
{
_AppDomain domain = null;
V2Host.NextDomain(hDomainEnum, out domain);
if (domain == null) break;
result.Add(domain);
}
V2Host.CloseEnum(hDomainEnum);
return result;
} private static Guid CLSID_CLRMetaHost = new Guid(0x9280188d, 0xe8e, 0x4867, 0xb3, 0xc, 0x7f, 0xa8, 0x38, 0x84, 0xe8, 0xde);
private static Guid IID_CLRMetaHost = new Guid(0xD332DB9E, 0xB9B3, 0x4125, 0x82, 0x07, 0xA1, 0x48, 0x84, 0xF5, 0x32, 0x16);
private static Guid IID_CLRRuntimeInfo = new Guid(0xBD39D1D2, 0xBA2F, 0x486a, 0x89, 0xB0, 0xB4, 0xB0, 0xCB, 0x46, 0x68, 0x91);
private static Guid CLSID_CorRuntimeHost = new Guid(0xcb2f6723, 0xab3a, 0x11d2, 0x9c, 0x40, 0x00, 0xc0, 0x4f, 0xa3, 0x0a, 0x3e);
private static Guid IID_CorRuntimeHost = new Guid(0xcb2f6722, 0xab3a, 0x11d2, 0x9c, 0x40, 0x00, 0xc0, 0x4f, 0xa3, 0x0a, 0x3e); [DllImport("mscoree.dll")]
private static extern int CLRCreateInstance(ref Guid clsid, ref Guid iid,
[MarshalAs(UnmanagedType.Interface)] out object ptr); [ComImport, Guid("D332DB9E-B9B3-4125-8207-A14884F53216"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface ICLRMetaHost
{
[return: MarshalAs(UnmanagedType.Interface)]
object GetRuntime(string version, ref Guid iid);
// Rest omitted
} [ComImport, Guid("BD39D1D2-BA2F-486a-89B0-B4B0CB466891"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface ICLRRuntimeInfo
{
void GetVersionString(char[] buffer, int bufferLength);
void GetRuntimeDirectory(char[] buffer, int bufferLength);
bool IsLoaded(IntPtr hProcess);
void LoadErrorString(uint id, char[] buffer, int bufferLength, int lcid);
void LoadLibrary(string path, out IntPtr hMdodule);
void GetProcAddress(string name, out IntPtr addr);
[return: MarshalAs(UnmanagedType.Interface)]
object GetInterface(ref Guid clsid, ref Guid iid);
bool IsLoadable();
void SetDefaultStartupFlags(uint flags, string configFile);
void GetDefaultStartupFlags(out uint flags, char[] configFile, int configFileLength);
void BindAsLegacyV2Runtime();
void IsStarted(out bool started, out uint flags);
} [ComImport, Guid("CB2F6722-AB3A-11d2-9C40-00C04FA30A3E"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface ICorRuntimeHost
{
void CreateLogicalThreadState();
void DeleteLogicalThreadState();
void SwitchinLogicalThreadState(IntPtr cookie);
void SwitchoutLogicalThreadState(out IntPtr cookie);
void LocksHeldByLogicalThread(out int count);
void MapFile(IntPtr hFile, out IntPtr address);
void GetConfiguration(out IntPtr config);
void Start();
void Stop();
void CreateDomain(string name, object identity, out _AppDomain domain);
void GetDefaultDomain(out _AppDomain domain);
void EnumDomains(out IntPtr hEnum);
void NextDomain(IntPtr hEnum, out _AppDomain domain);
void CloseEnum(IntPtr hEnum);
// rest omitted
}
}
}
}

跨 Appdomain 对象共享的更多相关文章

  1. .NET跨AppDomain访问对象

    什么是AppDomain? 我们都知道windows进程,它起到应用程序隔离的作用,带来的好处是,当某个进程发生错误的时候,不会影响其他的进程,系统也不会受到影响.但是,创建windows进程的代价是 ...

  2. 跨JavaScript对象作用域调用setInterval方法

    跨JavaScript对象作用域调用setInterval方法: var id = window.setInterval(function() {foofunc.call(this);}, 200);

  3. redis 系列15 数据对象的(类型检查,内存回收,对象共享)和数据库切换

    一.  概述 对于前面的五章中,已清楚了数据对象的类型以及命令实现,其实还有一种数据对象为HyperLogLog,以后需要用到再了解.下面再了解类型检查,内存回收,对象共享,对象的空转时长. 1.1 ...

  4. Apex的对象共享

    Apex的对象共享 在Apex中,每个对象都有一个"共享"对象,其中存储了该对象的共享设定. 这种共享对象以"share"结尾.比如Account的共享对象是A ...

  5. 利用localStorage事件来跨标签页共享sessionStorage

    //干货 利用localStorage事件来跨标签页共享sessionStorage //因为cookie保存字节数量有限,很多童鞋考虑用html5 storage来保存临时数据,Sessionsto ...

  6. PHP实现跨服务器session共享的方法教程

    今天带来PHP实现跨服务器session共享的方法教程. 本文实例讲述了PHP实现cookie跨域session共享的方法.分享给大家供大家参考,具体如下: 做过web开发的小伙伴们都了解cookie ...

  7. [C++] 所有该类的对象共享静态类成员变量

    问:智能指针可以对指针的引用数量进行计数,一个智能指针释放时,别的智能指针怎么知道的? 同一类的对象共享同一变量最简单的方法是静态变量: 不像普通的变量,静态成员变量是被所有类对象共享的,不同的对象可 ...

  8. 跨域cookies 共享

    这是由于,本地调试.涉及到cookies的问题 想要跨域使用的问题 vue 中的mian.js中放入下面代码 import axios from 'axios' axios.defaults.with ...

  9. 【Flutter】功能型组件之跨组件状态共享

    前言   在Flutter开发中,状态管理是一个永恒的话题.   一般的原则是:如果状态是组件私有的,则应该由组件自己管理:如果状态要跨组件共享,则该状态应该由各个组件共同的父元素来管理.   对于组 ...

随机推荐

  1. python+selenium破解极验验证登录

    1.前言: 目前很多网站会在正常的账号密码认证之外加一些验证码,以此来明确区分人/机行为,最典型的就是极验滑动验证.(如下图) 这里我们以简单实例说明如何实现自动校验类似验证. 2.步骤: 1)点击验 ...

  2. 使用kong-dashboard

    具体命令行操作只需按照官网一步一步来即可(https://docs.konghq.com/1.4.x/getting-started/configuring-a-service/),这里介绍图形化操作 ...

  3. mysql远程不能连接问题

    解决Navicat无法连接到腾讯云MySQL的问题 工具/原料   Navicat phpstudy 腾讯云 Xshell6 方法/步骤   1 1.首先远程连接进入服务器,在cmd中输入mysql ...

  4. python _str_方法

    _str_方法: 使用:如: class Car: def __init__(self,newWheelNum,newColor): self.wheelNum=newWheelNum self.co ...

  5. Java并发编程实战 第2章 线程安全性

    编写线程安全的 代码,核心在与对共享的和可变的对象的状态的访问. 如果多个线程访问一个可变的对象时没有使用同步,那么就会出现错误.在这种情况下,有3中方式可以修复这个问题: 不在线程之间共享该状态变量 ...

  6. 使用XML的方式实现账户的CRUD

    1 需求和技术要求 1.1 需求 实现账户的CRUD. 1.2 技术要求 使用Spring的IOC实现对象的管理. 使用QueryRunner作为持久层的解决方案. 使用C3p0作为数据源. 2 环境 ...

  7. share point 已在此服务器场中安装 ID 为 15/b7a69889-1789-4855-b8bd-9a3b4cfd7fc0 的功能。请使用强制属性显式地重新安装此功能。

    部署步骤“添加解决方案”中出现错误: 已在此服务器场中安装 ID 为 15/b7a69889-1789-4855-b8bd-9a3b4cfd7fc0 的功能.请使用强制属性显式地重新安装此功能. 英文 ...

  8. rsync+inotify实时数据同步多目录实战

    rsync+inotify实时数据同步多目录实战       inotify配置是建立在rsync服务基础上的配置过程 操作系统 主机名 网卡eth0 默认网关 用途 root@58server1 1 ...

  9. C++ - C++简介

    一.C与C++ 一般来说,计算机要处理两个概念--算法和数据.C在面世时是过程性的语言,过程性的语言指的是程序的过程较比其他语言,会更加的有序可读(清晰性和可读性).因为它把程序分解成各个分支,并执行 ...

  10. Django简单操作

    一.静态文件配置 静态文件配置 STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR,'static') ] # 暴露给 ...