Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. AppDomain.DomainUnload never fired automatically

AppDomain.DomainUnload never fired automatically

Scheduled Pinned Locked Moved C#
questiontestingbeta-testingtutorial
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VizOne
    wrote on last edited by
    #1

    Hi! In my app I'd like to execute some code when an AppDomain is unloaded. I expected AppDomain.DomainUnload to be suitable for this, however the event never gets raised automatically - only if I call AppDomain.Unload with that AppDomain. Example:

    class Class1
    {
    static void Main(string[] args)
    {
    // subscribe to current domain
    AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);

    	// and for testing to another domain:
    
    	AppDomain domain = AppDomain.CreateDomain("Test");
    	domain.DomainUnload += new EventHandler(CurrentDomain\_DomainUnload);
    
        // if I uncomment this, the event is fired for 'domain':
    	//AppDomain.Unload(domain);
    }
    
    public static void CurrentDomain\_DomainUnload(object sender, EventArgs e)
    {
        Console.WriteLine("Unloading appdomain");
    	AppDomain domain = sender as AppDomain;
    	if(domain != null)
    		Console.WriteLine("... unloading domain is: " + domain.FriendlyName);
    }
    

    }

    I find this quite irritating. How can I implement some kind of per-AppDomain shutdown function? Thanks in advance. Regards, Andre Loker

    L 1 Reply Last reply
    0
    • V VizOne

      Hi! In my app I'd like to execute some code when an AppDomain is unloaded. I expected AppDomain.DomainUnload to be suitable for this, however the event never gets raised automatically - only if I call AppDomain.Unload with that AppDomain. Example:

      class Class1
      {
      static void Main(string[] args)
      {
      // subscribe to current domain
      AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);

      	// and for testing to another domain:
      
      	AppDomain domain = AppDomain.CreateDomain("Test");
      	domain.DomainUnload += new EventHandler(CurrentDomain\_DomainUnload);
      
          // if I uncomment this, the event is fired for 'domain':
      	//AppDomain.Unload(domain);
      }
      
      public static void CurrentDomain\_DomainUnload(object sender, EventArgs e)
      {
          Console.WriteLine("Unloading appdomain");
      	AppDomain domain = sender as AppDomain;
      	if(domain != null)
      		Console.WriteLine("... unloading domain is: " + domain.FriendlyName);
      }
      

      }

      I find this quite irritating. How can I implement some kind of per-AppDomain shutdown function? Thanks in advance. Regards, Andre Loker

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      What about the ProcessExited event?

      top secret AdvancedTextBox

      V 1 Reply Last reply
      0
      • L leppie

        What about the ProcessExited event?

        top secret AdvancedTextBox

        V Offline
        V Offline
        VizOne
        wrote on last edited by
        #3

        ProcessExited only works for the main AppDomain (and even then, I find strange bevahvior to occur). Regards, Andre

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups