AppDomain和.NET中的进程 [英] AppDomain and Process in .NET

查看:58
本文介绍了AppDomain和.NET中的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.Net中的AppDomains和Process是什么?哪些是超集?什么是在.Net中使用AppDomains和Process以及如何使用它们?请通过一个恰当而简单的例子来解释。

What are AppDomains and Process in .Net and which is the superset? Whats is use of AppDomains and Process in .Net and How to use them? Please explain by a proper and simple example.

推荐答案

该过程包含一个或多个应用程序域。



应用程序域提供与进程相同的隔离级别:隔离应用程序域数据的地址空间;为了传递数据,使用了一种特殊的类似IPC的机制(真正的IPC当然可以用于传递数据,例如套接字,命名管道等,但为什么?)。



这种额外的分离级别的一个非常重要但鲜为人知的原因是一个基本的.NET功能,如带反射的动态装配加载。问题是:您可以加载程序集,但无法卸载它。这是重要的安全功能。如果你需要一些可重新加载的组件,比如插件,你可以一遍又一遍地加载程序集,但是没有办法卸载它们,这是一个很大的内存泄漏。 (是的,尽管存在托管内存,但.NET中可能存在内存泄漏;这只是创建泄漏的方法之一。)在这种情况下该怎么办?您可以创建单独的Application Domain,在其中加载临时程序集,使用它,当您需要重新加载程序集时,可以卸载整个Application Domain。为什么这样安全?因为应用程序域是孤立的;所以你不可能使用任何可以接受但已经卸载的东西。



为了进一步了解Application Domain的想法,请阅读它们:

http://en.wikipedia.org/wiki/Application_domain [ ^ ],

http://msdn.microsoft.com/en-us/library/dah4cwez.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/yb506139.aspx [ ^ ]。







对于示例,每个引用的主题都有代码示例从这个MSDN页面:

http://msdn.microsoft.com/en -us / library / yb506139.aspx [ ^ ]。



MSDN帮助页面中有更多示例。在你提出更有成效的问题之前,你真的需要看到它们。



-SA
The process contains one or more Application Domains.

The application domains provides the same level of isolation as processes: address spaces of Application Domain data are isolated; to pass data, a special simplified IPC-like mechanisms are used (and "real" IPC could of course be used to pass data, such as sockets, named pipes, etc, but why?).

One of the very important but little known reasons for such additional level of separation is such a fundamental .NET feature as the dynamic assembly loading with reflection. The problem is: you can load an assembly, but you cannot unload it. This is the important security feature. If you need some reloadable components, such as plug-ins, you can load assemblies over and over, but there is no a way to unload them, which is a big memory leak. (Yes, there can be memory leaks in .NET, despite of managed memory; this is just one of the ways to create a leak.) What to do in this case? You can create a separate Application Domain, load your temporary assembly in it, use it, and when you need to re-load the assembly, you can unload the whole Application Domain. Why is that safe? Because Application Domains are isolated; so you cannot possibly use anything acceptable but already unloaded.

For further understanding of Application Domain ideas, please read about them:
http://en.wikipedia.org/wiki/Application_domain[^],
http://msdn.microsoft.com/en-us/library/dah4cwez.aspx[^],
http://msdn.microsoft.com/en-us/library/yb506139.aspx[^].



As to "examples", there are code samples on each of the topics referenced from this MSDN page:
http://msdn.microsoft.com/en-us/library/yb506139.aspx[^].

There are more example in MSDN help pages. You really need to see them, before you can ask more productive questions.

—SA


这篇关于AppDomain和.NET中的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆