• <legend id='K2wha'><style id='K2wha'><dir id='K2wha'><q id='K2wha'></q></dir></style></legend>
    1. <tfoot id='K2wha'></tfoot>

      <small id='K2wha'></small><noframes id='K2wha'>

      <i id='K2wha'><tr id='K2wha'><dt id='K2wha'><q id='K2wha'><span id='K2wha'><b id='K2wha'><form id='K2wha'><ins id='K2wha'></ins><ul id='K2wha'></ul><sub id='K2wha'></sub></form><legend id='K2wha'></legend><bdo id='K2wha'><pre id='K2wha'><center id='K2wha'></center></pre></bdo></b><th id='K2wha'></th></span></q></dt></tr></i><div id='K2wha'><tfoot id='K2wha'></tfoot><dl id='K2wha'><fieldset id='K2wha'></fieldset></dl></div>
        <bdo id='K2wha'></bdo><ul id='K2wha'></ul>

        卸载使用 Assembly.LoadFrom() 加载的程序集

        Unloading the Assembly loaded with Assembly.LoadFrom()(卸载使用 Assembly.LoadFrom() 加载的程序集)
        <i id='rRtwm'><tr id='rRtwm'><dt id='rRtwm'><q id='rRtwm'><span id='rRtwm'><b id='rRtwm'><form id='rRtwm'><ins id='rRtwm'></ins><ul id='rRtwm'></ul><sub id='rRtwm'></sub></form><legend id='rRtwm'></legend><bdo id='rRtwm'><pre id='rRtwm'><center id='rRtwm'></center></pre></bdo></b><th id='rRtwm'></th></span></q></dt></tr></i><div id='rRtwm'><tfoot id='rRtwm'></tfoot><dl id='rRtwm'><fieldset id='rRtwm'></fieldset></dl></div>

      1. <small id='rRtwm'></small><noframes id='rRtwm'>

        <tfoot id='rRtwm'></tfoot>
          <tbody id='rRtwm'></tbody>
          • <bdo id='rRtwm'></bdo><ul id='rRtwm'></ul>
            <legend id='rRtwm'><style id='rRtwm'><dir id='rRtwm'><q id='rRtwm'></q></dir></style></legend>

                  本文介绍了卸载使用 Assembly.LoadFrom() 加载的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要检查加载 dll 后运行 GetTypes() 的时间量.代码如下.

                  I need to check the time amount to run GetTypes() after loading the dll. The code is as follows.

                  Assembly assem = Assembly.LoadFrom(file);
                  sw = Stopwatch.StartNew();
                  var types1 = assem.GetTypes();
                  sw.Stop();
                  double time1 = sw.Elapsed.TotalMilliseconds;
                  

                  我想卸载并重新加载 dll 以检查再次运行 GetTypes() 所花费的时间.

                  I'd like to unload and reload the dll to check the time to spend in running GetTypes() again.

                  • 如何卸载?assem = null 够好吗?
                  • 有没有明确的方法来调用垃圾收集器来回收分配给 assem 的资源?

                  推荐答案

                  不幸的是,一旦程序集被加载,您就无法卸载它.但是您可以卸载 AppDomain.您可以做的是创建一个新的 AppDomain (AppDomain.CreateDomain(...) ),将程序集加载到此 appdomain 中以使用它,然后在需要时卸载 AppDomain.卸载 AppDomain 时,将卸载所有已加载的程序集.(请参阅参考)

                  Unfortunately you can not unload an assembly once it is loaded. But you can unload an AppDomain. What you can do is to create a new AppDomain (AppDomain.CreateDomain(...) ), load the assembly into this appdomain to work with it, and then unload the AppDomain when needed. When unloading the AppDomain, all assemblies that have been loaded will be unloaded. (See reference)

                  要调用垃圾收集器,可以使用

                  To call the garbage collector, you can use

                  GC.Collect(); // collects all unused memory
                  GC.WaitForPendingFinalizers(); // wait until GC has finished its work
                  GC.Collect();
                  

                  GC 在后台线程中调用终结器,这就是为什么您必须等待并再次调用 Collect() 以确保您删除了所有内容.

                  GC calls the finalizers in a background thread, that's why you have to wait and call Collect() again to make sure you deleted everything.

                  这篇关于卸载使用 Assembly.LoadFrom() 加载的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                  <legend id='y1mhj'><style id='y1mhj'><dir id='y1mhj'><q id='y1mhj'></q></dir></style></legend>

                  <small id='y1mhj'></small><noframes id='y1mhj'>

                      <tbody id='y1mhj'></tbody>
                    1. <tfoot id='y1mhj'></tfoot>

                      <i id='y1mhj'><tr id='y1mhj'><dt id='y1mhj'><q id='y1mhj'><span id='y1mhj'><b id='y1mhj'><form id='y1mhj'><ins id='y1mhj'></ins><ul id='y1mhj'></ul><sub id='y1mhj'></sub></form><legend id='y1mhj'></legend><bdo id='y1mhj'><pre id='y1mhj'><center id='y1mhj'></center></pre></bdo></b><th id='y1mhj'></th></span></q></dt></tr></i><div id='y1mhj'><tfoot id='y1mhj'></tfoot><dl id='y1mhj'><fieldset id='y1mhj'></fieldset></dl></div>
                          • <bdo id='y1mhj'></bdo><ul id='y1mhj'></ul>