在c#项目中,是否经常使用AppDomain? [英] In c# project, Is AppDomain frequently used ?

查看:84
本文介绍了在c#项目中,是否经常使用AppDomain?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我已经了解了AppDomain,但我无法理解如何在真实项目中使用它。

默认AppDomain对于一个进程是不够的?

在这种情况下,创建一个新的AppDomain更合适吗?

希望有人可以解决我的问题。谢谢!!!!

Recently, I've learned about AppDomain, But I can't understand how to use it in the real project.
Is the Default AppDomain not enough for one process?
In which case, creating a new AppDomain is more suitable?
Hope someone can solve my question. Thank you!!!!

推荐答案

我个人不使用AppDomains,但接下来 - 我不接触可能失败的任务:我更喜欢写一些不使用防御性编程技术。



如果查看MSDN文档:http://msdn.microsoft.com/en-gb/library/system.appdomain.aspx [ ^ ]非常清楚地说明:



由AppDomain对象表示的应用程序域有助于为执行托管代码提供隔离,卸载和安全边界。

  • 使用应用程序域隔离可能导致进程失败的任务。如果正在执行任务的AppDomain的状态变得不稳定,则可以卸载AppDomain而不会影响该进程。当进程必须长时间运行而不重新启动时,这很重要。您还可以使用应用程序域来隔离不应共享数据的任务。
I don't personally use AppDomains, but then - I don't interface with tasks that are liable to fail: I prefer to write ones that don't by using defensive programming techniques.

If you look at the MSDN documentation: http://msdn.microsoft.com/en-gb/library/system.appdomain.aspx[^] it's pretty clearly stated:

Application domains, which are represented by AppDomain objects, help provide isolation, unloading, and security boundaries for executing managed code.
  • Use application domains to isolate tasks that might bring down a process. If the state of the AppDomain that's executing a task becomes unstable, the AppDomain can be unloaded without affecting the process. This is important when a process must run for long periods without restarting. You can also use application domains to isolate tasks that should not share data.
  • 如果程序集已加载到默认应用程序域中,则不能在进程运行时从内存中卸载。但是,如果打开第二个应用程序域以加载并执行程序集,则卸载该应用程序域时将卸载该程序集。使用此技术可以最大限度地减少偶尔使用大型DLL的长时间运行进程的工作集。


IMO尽可能让框架管理器成为您的应用程序域。
IMO, as far as possible, let the framework manager your application domains.


这篇关于在c#项目中,是否经常使用AppDomain?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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