在c#项目中,是否经常使用AppDomain?

编程入门 行业动态 更新时间:2024-10-27 18:23:45
本文介绍了在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文档:msdn.microsoft/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: msdn.microsoft/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?

本文发布于:2023-11-17 06:22:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   AppDomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!