最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net中关于AppDomain遍历的方法
时间:2011-01-11 编辑:简简单单 来源:一聚教程网
对于mscoree.dll程序集的引用请使用com引用:c:windowsmicrosoft.netframeworkvxxxxxxmscoree.tlb
public static ilist
getappdomains()
{
ilistlist = new list ();
intptr enumhandle = intptr.zero;
corruntimehostclass host = new corruntimehostclass();
try
{
host.enumdomains(out enumhandle);
object domain = null;
while (true)
{
host.nextdomain(enumhandle, out domain);
if (domain == null) break;
appdomain appdomain = (appdomain)domain;
list.add(appdomain);
}
return list;
}
catch (exception e)
{
return null;
}
finally
{
host.closeenum(enumhandle);
marshal.releasecomobject(host);
}
}
.net framework居然没有提供托管的接口来获取当前进程中的其它appdomain!所以,我们只有借助承载接口(hosting interfaces)来完成这事了。
在mscoree.dll中,.net 1.0提供了一个icorruntimehost接口,该接口中有enumdomains和nextdomain方法,而幸运的是:mscoree.dll中居然直接提供了一个public的实现:corruntimehostclass。所以,我们只需要新建一个corruntimehostclass然后调用enumdomains和nextdomain
相关文章
- asp.net 遍历一个所有控件 07-30
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10