Esempio n. 1
0
 /// <summary>
 /// Destroy the AppDomain.
 /// </summary>
 private void DestroyDomain(bool disposing)
 {
     Debug.WriteLine("Unloading AppDomain '" + mAppDomain.FriendlyName +
                     "', id=" + mAppDomain.Id + ", disposing=" + disposing);
     if (mKeepAliveTimer != null)
     {
         mKeepAliveTimer.Stop();
         mKeepAliveTimer.Dispose();
         mKeepAliveTimer = null;
     }
     if (mPluginManager != null)
     {
         mPluginManager.Dispose();
         mPluginManager = null;
     }
     if (mAppDomain != null)
     {
         // We can't simply invoke AppDomain.Unload() from a finalizer.  The unload is
         // handled by a thread that won't run at the same time as the finalizer thread,
         // so if we got here through finalization we will deadlock.  Fortunately the
         // runtime sees the situation and throws an exception out of Unload().
         //
         // If we don't have a finalizer, and we forget to make an explicit cleanup
         // call, the AppDomain will stick around and keep the DLL files locked, which
         // could be annoying if the user is trying to iterate on extension script
         // development.
         //
         // So we use a workaround from https://stackoverflow.com/q/4064749/294248
         // and invoke it asynchronously.
         if (disposing)
         {
             AppDomain.Unload(mAppDomain);
         }
         else
         {
             new Action <AppDomain>(AppDomain.Unload).BeginInvoke(mAppDomain, null, null);
         }
         mAppDomain = null;
     }
 }